问题说明:当html页面的<form>属性中有enctype="multipart/form-data" 时 在jsp页面不能用request.getParameter("name");获得html表单中的数据
例:<form method=post action="addNew_hxxm.jsp" name="form1"enctype="multipart/form-data">
解决办法:在jsp页面的<body>下加上以下代码
<%
mySmartUpload.initialize(pageContext);
mySmartUpload.service(request,response);
mySmartUpload.upload();
String i_xmmc = mySmartUpload.getRequest().getParameter("xmmc");//取单个参数单个值
%>
关于enctype="multipart/form-data"的说明
表单中enctype="multipart/form-data"的意思,是设置表单的MIME编码。默认情况,这个编码格式是application/x-www-form-urlencoded,不能用于文件上传;只有使用了multipart/form-data,才能完整的传递文件数据,进行下面的操作.
enctype="multipart/form-data"是上传二进制数据;
form里面的input的值以2进制的方式传过去,所以request就得不到值了。
取表单值加入数据库时,用到下面的:
SmartUpload su = new SmartUpload();//新建一个SmartUpload对象
su.getRequest().getParameterValues();取数组值
su.getRequest().getParameter( );取单个参数单个值