当前位置: 技术问答>java相关
各位,做的个人简历有照片上传问题??急
来源: 互联网 发布时间:2015-08-25
本文导语: 我用的win2000+tomcat4.0+jdk1.3 数据库是oracle8.05, 做的职工简历,附带照片,怎么实现照片传到数据库字段, 如果有完整的代码,肯定给分!!!!!谢谢各位 | 什么都能上传 import javax.servlet.*; i...
我用的win2000+tomcat4.0+jdk1.3 数据库是oracle8.05,
做的职工简历,附带照片,怎么实现照片传到数据库字段,
如果有完整的代码,肯定给分!!!!!谢谢各位
做的职工简历,附带照片,怎么实现照片传到数据库字段,
如果有完整的代码,肯定给分!!!!!谢谢各位
|
什么都能上传
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import com.neusoft.ExtendLibraries.ExtendConfig.configInfo;
public class ImportServlet extends HttpServlet {
private static final String CONTENT_TYPE = "text/html; charset=GBK";
private static final int ONE_MEG = 2048*1024;
//Initialize global variables
public void init() throws ServletException {
}
//Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doPost(request,response);
}
//Process the HTTP Post request
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
int buffsize = 1024*8;
int contentLength = request.getContentLength();
// Hashtable pageItems = null;
// value chosen to limit denial of service - 2 MB, in this case
if (contentLength > ONE_MEG){
System.out.println ("contentLength > ONE_MEG");
response.setContentType("text/html");
ServletOutputStream out = response.getOutputStream();
out.println("Too big");
out.println("错误 - 文件大于2M!");
out.println("");
out.close();
}
else{
HttpSession session = request.getSession(true);
int status=0;//status=0:非正文;status=1:分隔符;status=2:文件内容;status=3:其它内容
String ContentType=request.getHeader("content-type");
String boundary=ContentType.substring(ContentType.indexOf("boundary=")+9);
String fileName="";
String itemName="";
String lastItem="";
Properties pp = new Properties();
try{
pp = configInfo.getConfigObj();
}catch(Exception e){
}
String strPath=pp.getProperty("OutputPath");// "D:\Application_Studio\JTP\lib\";
ServletInputStream in = request.getInputStream();
byte[] b = new byte[buffsize];
byte[] byContent = new byte[contentLength];
int result;
int totalRead = 0;
FileOutputStream fileout = null;
try{
result = in.readLine(b, 0, b.length);
while (result != -1){
String rowStr=new String(b,0,result);
if (IsBoundary(rowStr,boundary)){ //遇到分割符
switch(status){
case 0:break;
case 1:break;
case 2:
if ( totalRead!=0&!fileName.equals("")){
fileout =new FileOutputStream(strPath+fileName);
fileout.write(byContent, 0, totalRead);
totalRead=0 ;
}
break;
case 3:
String itemContent=new String(byContent,0,totalRead);
if (itemName.equals(lastItem)){
String sval =(String) session.getAttribute (itemName);
sval+=";"+ itemContent;
session.setAttribute(itemName, sval);
}
else{
session.setAttribute(itemName, itemContent);
}
lastItem=itemName;
break;
}
totalRead=0;
status=0;
}
else if ( status
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import com.neusoft.ExtendLibraries.ExtendConfig.configInfo;
public class ImportServlet extends HttpServlet {
private static final String CONTENT_TYPE = "text/html; charset=GBK";
private static final int ONE_MEG = 2048*1024;
//Initialize global variables
public void init() throws ServletException {
}
//Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doPost(request,response);
}
//Process the HTTP Post request
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
int buffsize = 1024*8;
int contentLength = request.getContentLength();
// Hashtable pageItems = null;
// value chosen to limit denial of service - 2 MB, in this case
if (contentLength > ONE_MEG){
System.out.println ("contentLength > ONE_MEG");
response.setContentType("text/html");
ServletOutputStream out = response.getOutputStream();
out.println("Too big");
out.println("错误 - 文件大于2M!");
out.println("");
out.close();
}
else{
HttpSession session = request.getSession(true);
int status=0;//status=0:非正文;status=1:分隔符;status=2:文件内容;status=3:其它内容
String ContentType=request.getHeader("content-type");
String boundary=ContentType.substring(ContentType.indexOf("boundary=")+9);
String fileName="";
String itemName="";
String lastItem="";
Properties pp = new Properties();
try{
pp = configInfo.getConfigObj();
}catch(Exception e){
}
String strPath=pp.getProperty("OutputPath");// "D:\Application_Studio\JTP\lib\";
ServletInputStream in = request.getInputStream();
byte[] b = new byte[buffsize];
byte[] byContent = new byte[contentLength];
int result;
int totalRead = 0;
FileOutputStream fileout = null;
try{
result = in.readLine(b, 0, b.length);
while (result != -1){
String rowStr=new String(b,0,result);
if (IsBoundary(rowStr,boundary)){ //遇到分割符
switch(status){
case 0:break;
case 1:break;
case 2:
if ( totalRead!=0&!fileName.equals("")){
fileout =new FileOutputStream(strPath+fileName);
fileout.write(byContent, 0, totalRead);
totalRead=0 ;
}
break;
case 3:
String itemContent=new String(byContent,0,totalRead);
if (itemName.equals(lastItem)){
String sval =(String) session.getAttribute (itemName);
sval+=";"+ itemContent;
session.setAttribute(itemName, sval);
}
else{
session.setAttribute(itemName, itemContent);
}
lastItem=itemName;
break;
}
totalRead=0;
status=0;
}
else if ( status
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
站内导航:
特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!