Meaningless Drivel is fun!*
The moose likes Struts and the fly likes help!!!!problem about upolad struts' FormFile Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "help!!!!problem about upolad struts Watch "help!!!!problem about upolad struts New topic
Author

help!!!!problem about upolad struts' FormFile

charlse li
Greenhorn

Joined: Aug 03, 2004
Posts: 14
when upload txt file ,it's ok. however, when upload other file type,,it goes wrong: my email: sunrisefe@126.com
for html file:java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]第 33 行: 'http:' 附近有语法错误。

for pictures::java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]字符串 '???JFIF,,' 之前有未闭合的引号。

上传WORD时:java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]字符串 '邢唷??' 之前有未闭合的引号。

my action as follows:

package com.wch;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletException;

import java.io.IOException;
import java.io.FileNotFoundException;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;

import java.sql.*;

import org.apache.struts.upload.FormFile;


//操作数据库的Action..
public class BaoMingAction extends Action
{
private Connection conn;
public ActionForward execute(ActionMapping mapping,
ActionForm form, HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
{
BaoMingForm baoMingForm=(BaoMingForm)form;
BaoMing baoMing=new BaoMing();
baoMing=baoMingForm.getBaoMing();

String encoding = request.getCharacterEncoding();
if ((encoding != null) && (encoding.equalsIgnoreCase("utf-8")))
{
response.setContentType("text/html; charset=utf-8");
}


//retrieve the date from BaoMingForm

String registerTime1=baoMing.getRegisterTime();
FormFile photo1=baoMing.getPhoto();
String userName1=baoMing.getUserName();
String identification1=baoMing.getIdentification();
String sex1=baoMing.getSex();
String birth1=baoMing.getBirth();
String city1=baoMing.getCity();
String gongZhong1=baoMing.getGongZhong();
String eduLevel1=baoMing.getEduLevel();
float jobAge1=baoMing.getJobAge();
String workName1=baoMing.getWorkName();
String department1=baoMing.getDepartment();
String workPlace1=baoMing.getWorkPlace();
String jobResume1=baoMing.getJobResume();
int techLevel1=baoMing.getTechLevel();
int forTechLevel1=baoMing.getForTechLevel();
String comment1=baoMing.getComment();

if((photo1.getFileSize())>(1024*1024))
{
ActionErrors errors=new ActionErrors();
ActionError error=new ActionError("errors.baoming.file-greater.than.1M");
errors.add(errors.GLOBAL_ERROR,error);
saveErrors(request,errors);

return(mapping.findForward("failure"));
}
else
{
try{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
InputStream stream = photo1.getInputStream();
byte[] buffer = new byte[8192];
int bytesRead = 0;
String data = null;
while ((bytesRead = stream.read(buffer, 0, 8192)) != -1)
{
baos.write(buffer, 0, bytesRead);
}
//data = new String(baos.toByteArray());
stream.close();


//the sql statement to operate db.
String sqlQuery="select * from hangong_info where identification='"+baoMing.getIdentification()+"'";

String sqlInsert1="insert into hangong_info(registerTime,photo,userName,identification,sex,birth,city,gongZhong,eduLevel,jobAge,workName,department,workPlace,jobResume,techLevel,forTechLevel,comment)";
String sqlInsert2="values('"+registerTime1+"','"+baos+"','"+userName1+"','"+identification1+"','"+sex1+"','"+birth1+"','"+city1+"','"+gongZhong1+"','"+eduLevel1+"',"+jobAge1+",'"+workName1+"','"+department1+"','"+workPlace1+"','"+jobResume1+"',"+techLevel1+","+forTechLevel1+",'"+comment1+"')";

String sqlUpdate="update hangong_info set registerTime='"+registerTime1+"',photo='"+baos+"',userName='"+userName1+"',identification='"+identification1+"',sex='"+sex1+"',birth='"+birth1+"',city='"+city1+"',gongZhong='"+gongZhong1+"',eduLevel='"+eduLevel1+"',jobAge='"+jobAge1+"',workName='"+workName1+"',department='"+department1+"',workPlace='"+workPlace1+"',jobResume='"+jobResume1+"',techLevel='"+techLevel1+"',forTechLevel='"+forTechLevel1+"',comment='"+comment1+"' where identification='"+identification1+"'";

conn=DatabaseConn.getConnection();
Statement stmt=conn.createStatement();
if(stmt.executeQuery(sqlQuery).next())
{
stmt.executeUpdate(sqlUpdate);
return(mapping.findForward("baoming_success"));
}
else
{
stmt.executeUpdate(sqlInsert1+sqlInsert2);
return(mapping.findForward("baoming_success"));
}


}
catch (FileNotFoundException fnfe)
{
fnfe.printStackTrace();
ActionErrors errors=new ActionErrors();
ActionError error=new ActionError("errors.baoming.FileNotFoundException");
errors.add(errors.GLOBAL_ERROR,error);
saveErrors(request,errors);

return(mapping.findForward("failure"));
}
catch (IOException ioe)
{
ioe.printStackTrace();
ActionErrors errors=new ActionErrors();
ActionError error=new ActionError("errors.baoming.IOException");
errors.add(errors.GLOBAL_ERROR,error);
saveErrors(request,errors);

return(mapping.findForward("failure"));
}
catch (Exception e)
{
e.printStackTrace();
ActionErrors errors=new ActionErrors();
ActionError error=new ActionError("errors.baoming");
errors.add(errors.GLOBAL_ERROR,error);
saveErrors(request,errors);

return(mapping.findForward("failure"));
}

}





}
}
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
What kind of a column is 'photo'? If you're storing binary files in the database, you should use a BLOB column.


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: help!!!!problem about upolad struts' FormFile
 
Similar Threads
ActionError issue
jsp access exception
struts, error reporting
ActionErrors (Struts)
logic:iterate in struts