首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

求教!想实现上传图片功能,通过String ICP=su.getRequest().getParameter("ICP")无法获取值解决方案

2012-03-17 
求教!想实现上传图片功能,通过String ICPsu.getRequest().getParameter(ICP)无法获取值我想实现图片上

求教!想实现上传图片功能,通过String ICP=su.getRequest().getParameter("ICP")无法获取值
我想实现图片上传的功能,但是表单的值一直传递不了,源代码如下(不规范,见谅!):
register.jsp:

<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>supplierManagement</title>
</head>

<body>
<form action="register_deal.jsp" method="post" enctype="multipart/form-data" name="form13" id="form13">
  <table width="409">
  <tr>
  <th width="108" scope="col">ICP备案号</th>
  <th width="289" scope="col"><div align="left">
  <input type="text" name="ICP" />
  </div></th>
  </tr>
  <tr>
  <th scope="row">名称</th>
  <td><input type="text" name="name" /></td>
  </tr>
  <tr>
  <th scope="row">公司简介</th>
  <td><textarea name="brief"></textarea></td>
  </tr>
  <tr>
  <th scope="row">供应品</th>
  <td><select name="material">
  <option>蔬菜</option>
  <option>肉类</option>
  </select>
  </td>
  </tr>
  <tr>
  <th scope="row">报价</th>
  <td><input type="text" name="price" /></td>
  </tr>
  <tr>
  <th scope="row">地址</th>
  <td><input type="text" name="address" /></td>
  </tr>
  <tr>
  <th scope="row">电话</th>
  <td><input type="text" name="telephone" /></td>
  </tr>
  <tr>
  <th scope="row">邮箱</th>
  <td><input type="text" name="email" /></td>
  </tr>
  <tr>
  <th scope="row">合格证</th>
  <td><input type="file" name="certification" /></td>
  </tr>
  <tr>
  <th scope="row">检疫合格证</th>
  <td><input type="file" name="certification2" /></td>
  </tr>
  <tr>
  <th scope="row"><input type="submit" name="Submit3" value="提交" /></th>
  <td><div align="center">
  <input type="reset" name="Submit4" value="重置" />
  </div></td>
  </tr>
  </table>
</form>
</body>
</html>

deal_register.jsp:

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page contentType="text/html; charset=UTF-8" language="java" import="java.sql.*" errorPage="" %>


<%@ page import="com.jspsmart.upload.*"%>

<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
  <base href="<%=basePath%>">
   
  <title>My JSP 'register_deal.jsp' starting page</title>
   
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">  
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->

  </head>
  
  <body>
<%
Class.forName("com.mysql.jdbc.Driver").newInstance();
String url= "jdbc:mysql://localhost:3306/graduationproject?user=root&password=123&useUnicode=true&characterEncoding=GB2312";
Connection connection=DriverManager.getConnection(url); 
Statement statement = connection.createStatement();
request.setCharacterEncoding("gb2312");
SmartUpload su = new SmartUpload();
String ICP=su.getRequest().getParameter("ICP");
String name=su.getRequest().getParameter("name");
String brief=su.getRequest().getParameter("brief");
String material=su.getRequest().getParameter("material");
String price=su.getRequest().getParameter("price");
String address=su.getRequest().getParameter("address");
String telephone=su.getRequest().getParameter("telephone");
String email=su.getRequest().getParameter("email");
String certification=su.getRequest().getParameter("certification");
String certification2=su.getRequest().getParameter("certification2");

%>
<% 
out.print(ICP);
out.print(name);
out.print(brief);
out.print(material);
out.print(price);
out.print(address);
out.print(telephone);
out.print(email);
out.print(certification);
out.print(certification2);
 %>
  </body>
</html>


所有的输出都是null,为什么?怎么处理?

[解决办法]
SmartUpload su = new SmartUpload();

su.initialize(pageContext);
su.service(request, response);
su.setTotalMaxFileSize(100000000);
su.setAllowedFilesList("zip,rar");
su.setDeniedFilesList("exe,bat,jsp,htm,html,,");
su.upload();

String ICP=su.getRequest().getParameter("ICP");
String name=su.getRequest().getParameter("name");
String brief=su.getRequest().getParameter("brief");

。。。下面省略

下面这两句话是错误的,不可以这样获取路径名字,要js获取
String certification=su.getRequest().getParameter("certification");
String certification2=su.getRequest().getParameter("certification2");

建议获取上传后的名字
  
File myFile = su.getFiles().getFile(1);

String str = myFile.getFileName();



这里是SQL版块,建议楼主下次发java那里哦!!!
[解决办法]
<form action="register_deal.jsp" method="post" enctype="multipart/form-data" name="form13" id="form13">


你的action是register_deal.jsp
你的处理页面是deal_register.jsp?
[解决办法]
考察一下这样su.getRequest()获取的request
是不是真正页面请求过来包含数据的request

如果换成隐藏对象request直接获取会是什么结果
[解决办法]
查看你的form是否对应的是这个action


[解决办法]
没用过SmartUpload,帮顶

热点排行