用jspsmartupload上传文件,在表单中还有其他几个文本框,用一Servlet处理,上传文件正常,但其他几个文本框的值始终为null,请看里面的具体描

iamniou 2002-04-15 04:17:39
package dbservlet;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import java.sql.*;
import sun.jdbc.rowset.*;
import com.jspsmart.upload.*;

public class WriteWord extends HttpServlet
{
private ServletConfig config;
/**
* Init the servlet
*/
final public void init(ServletConfig config) throws ServletException
{
this.config = config;
}

int count=0; // Variables
SmartUpload mySmartUpload = new SmartUpload();

public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
try
{
mySmartUpload.initialize(config,request,response); // Initialization
mySmartUpload.setAllowedFilesList("jpg,gif,png,wma,wax,wmv,wvx,asf,asx,ram,rm,wav,avi,mpg,mpeg,mp3"); //Allow files
mySmartUpload.setDeniedFilesList("exe,bat,jsp,asp"); // DeniedFilesList can also be used
mySmartUpload.setDenyPhysicalPath(true); // Deny physical path
mySmartUpload.setMaxFileSize(1048576); // Only allow files smaller than 50000 bytes
mySmartUpload.upload(); // Upload
count = mySmartUpload.save("/images/images", mySmartUpload.SAVE_VIRTUAL); // Save the files with their original names in a virtual path of the web server

HttpSession userinfosession = request.getSession();
String UserID = (String)userinfosession.getValue("UserID");
String cName = (String)userinfosession.getValue("cName");

String icon = "/images/icon/"+request.getParameter("radiobutton")+".gif";
String subject = request.getParameter("subject");
String lWord = request.getParameter("lWord");
String file = request.getParameter("file");

java.util.Date datetime = new java.util.Date();
java.text.DateFormat fmt = java.text.DateFormat.getDateTimeInstance();
String wTime = fmt.format(datetime);
String ip = request.getRemoteAddr();

ConnectDB conndb = new ConnectDB();
conndb.setUpdate("insert into leaveword (UserID,cName,icon,subject,lWord,picture,wTime,ip) values ("+
"'"+UserID+"'"+","+"'"+cName+"'"+","+"'"+icon+"'"+","+"'"+subject+"'"+","+
"'"+lWord+"'"+","+"'"+file+"'"+","+"'"+wTime+"'"+","+"'"+ip+"'"+")");

request.setAttribute("count",String.valueOf(count));
RequestDispatcher rd = request.getRequestDispatcher("/leaveword/successword.jsp");
rd.forward(request,response);
}

catch (Exception ex)
{
System.err.println("发生错误:" + ex.getMessage());
}

}
}


其中String icon ,String subject,String lWord ,String file(为表单中几个文本框的值)的值始终为null,怎么办? 表单的ENCTYPE为"multipart/form-data"
...全文
25 点赞 收藏 1
写回复
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
leonzhao 2002-04-15
这样:

String icon = "/images/icon/"+mySmartUpload.getRequest().getParameter("radiobutton")+".gif";
String subject = mySmartUpload.getRequest().getParameter("subject");
String lWord = mySmartUpload.getRequest().getParameter("lWord");
String file = mySmartUpload.getRequest().getParameter("file");
回复
发动态
发帖子
Web 开发
创建于2007-09-28

7.9w+

社区成员

Java Web 开发
申请成为版主
社区公告
暂无公告