在线急等,关于jspSmartUpload解决request.getparameter不能获得值的问题
在网上下载了一个子jspSmartUpload组件放在WEB-INF的lib目录下想解决既能实现文件上传又可以解决request.getparameter获得值的问题,但是不知该怎样能够解决获不到值的问题,麻烦各位帮忙解决,在下先谢谢啦
这是偶在javabean中的代码
public boolean addnews(Connection conn, HttpServletRequest request) {
boolean a = true;
try {
String title =request.getParameter( "title ");
String author = request.getParameter( "author ");
String riqi = request.getParameter( "riqi ");
String content = request.getParameter( "content ");
String typeid = request.getParameter( "typeid ");
Statement smt = conn.createStatement();
String sql1 = "insert into newstable(title,author,riqi,content,typeID)values( ' "+ title + " ', ' "+ author + " ', ' "+ riqi + " ', ' "+ content + " ', "+ typeid + ") ";
System.out.println(sql1);
smt.executeQuery(sql1);
} catch (Exception e) {
a = false;
}
return a;
}
------解决方案--------------------你的jsp页面中的form应该是这样写的吧: <form method= "post " name= "form " action= "add " enctype= "multipart/form-data "> 你加上了enctype= "multipart/form-data "这句话对吧。
你如果是这样使用的话在javabean中就不能用request.getparameter()这个方法,应该这样得到数据:
SmartUpload mySmartUpload =new SmartUpload();
mySmartUpload.initialize(this.getServletConfig(),request,response);
//mySmartUpload进行初始化,应该在你的servlet中进行,this代表你的servlet对象。
然后用mySmartUpload.getRequest().getParameter( "title ");得到数据。
------解决方案--------------------可以啊,用上面的就行了