toyysky 2004年12月21日
传递过来怎么就是null了?
程序1:
<%@page contentType="text/html;charset=GBK"%>
<%@page import="java.sql.*"%>
<%@ include file="/public/head.jsp"%>
<%@ include file="fdk.jsp"%>
<HTML>
<HEAD>
<script language="JavaScript">
function checkit(){
var theform;
theform=document.form1;

if (theform.pingp.value==""){
alert("品牌不能为空!");
theform.pingp.focus();
return false;}
if (theform.guige.value==""){
alert("规格不能为空!");
theform.guige.focus();
return false;}
if (theform.shuxin.value==""){
alert("属性不能为空!");
theform.shuxin.focus();
return false;}
if (theform.file.value==""){
alert("请您选择文件!");
theform.file.focus();
return false;}
theform.Submit();
}
</script>
<BODY >
<BR>
<FORM action="upload.jsp" encType=multipart/form-data method=post name="form1">
<TABLE cellspacing="0" cellpadding="0" width="760" border="1" bordercolorlight="#008000">
<TBODY>
<TR>
<TD width="300" height="30" bgcolor="#C0C0C0">
<p align="left"><FONT color=#000000 face=helv,helvetica size=1>  </FONT>  请选择上传产品的类型:</TD>
<TD width="500" height="25" bgcolor="#C0C0C0"><select size="1" name="leibie">
     <option>戒指</option>
<option> 耳环</option>
<option>发卡</option>
<option> 胸针</option>
<option>项链</option>
<option> 其它</option>
</select></TD></TR>
<TR>
<TD width="412" height="30" bgcolor="#C0C0C0">
<p align="left"><FONT color=#000000 face=helv,helvetica size=1>  </FONT>  请填写上传产品的品牌:</TD>
<TD bgcolor="#C0C0C0"><input type="text" name="pingp" size="20"></TD></TR>
<TR>
<TD width="412" height="30" bgcolor="#C0C0C0">
<p align="left"><FONT color=#000000 face=helv,helvetica size=1>  </FONT>  请填写上传产品的规格:</TD>
<TD bgcolor="#C0C0C0"><input type="text" name="guige" size="20"></TD></TR>
<TR>
<TD width="412" height="30" bgcolor="#C0C0C0">
<p align="left"><FONT color=#000000 face=helv,helvetica size=1> </FONT>  请添写上传产品的属性:</TD>
<TD bgcolor="#C0C0C0"><input type="text" name="shuxin" size="20"></TD></TR>
<TR>
<TD
align=right></TD></TR>
<TR>
<TD
align=right width="412" height="30" bgcolor="#C0C0C0">
<p align="left">  请选择上传的产品:</TD>
<TD
align=right bgcolor="#C0C0C0">
<INPUT size=25 type=file name="file" style="float: left">[文件限量不得超过500k]</TD></TR>
<TR>
<TD
align=right height="30" colspan="2" bgcolor="#C0C0C0">
<p align="center"><INPUT type=submit value=上传 name="Submit" onclick='return checkit()'>  
<input type=reset value=重填></TD>
</TR>
</TBODY>
</TABLE>
</FORM>
</BODY>
</body>
<center>
<%@ include file="/public/tatil.jsp"%>
</html>


程序2
传递完后得到上面传递过来的值,但是不知道怎么了都是null啊?
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.sql.*"%>
<jsp:useBean id="conn" scope="page" class="sanhe.conn"/>
<%@ page import="com.jspsmart.upload.*" %>
<%!
String myFileName="";
String FileId="";
String FileName="";
String pingp="";
String guige="";
String shuxin="";
SmartUpload mySmartUpload=new SmartUpload();
%>
<%
request.setCharacterEncoding("GBK");
com.jspsmart.upload.Request myRequest=mySmartUpload.getRequest();
FileName=myRequest.getParameter("leibie");
pingp=myRequest.getParameter("pingp");
guige=myRequest.getParameter("guige");
shuxin=myRequest.getParameter("shuxin");


//实例化上载bean
com.jspsmart.upload.SmartUpload mySmartUpload=new com.jspsmart.upload.SmartUpload();
//初始化
mySmartUpload.initialize(pageContext);
//设置上载的最大值
mySmartUpload.setMaxFileSize(500 * 1024*1024);
//上载文件
mySmartUpload.upload();
//循环取得所有上载的文件
for (int i=0;i<mySmartUpload.getFiles().getCount();i++){
//取得上载的文件
com.jspsmart.upload.File myFile = mySmartUpload.getFiles().getFile(i);
if (!myFile.isMissing())
{
//取得上载的文件的文件名
myFileName=myFile.getFileName();
//取得不带后缀的文件名
String suffix=myFileName.substring(0,myFileName.lastIndexOf('.'));
//取得后缀名
String ext= mySmartUpload.getFiles().getFile(0).getFileExt();
//取得文件的大小
int fileSize=myFile.getSize();
//保存路径
String aa=getServletContext().getRealPath("/")+"file\\";
String trace=aa+myFileName;
//取得别的参数
String explain=(String)mySmartUpload.getRequest().getParameter("text");
String send=(String)mySmartUpload.getRequest().getParameter("send");
//将文件保存在服务器端
myFile.saveAs(trace,mySmartUpload.SAVE_PHYSICAL);}}
conn.executeUpdate("insert into zhantu (LineId,FileName,pingp,guige,shuxin) values('"+ myFileName +"','" + FileName + "','" + pingp + "','" + guige + "','" + shuxin + "')");
out.println(myFileName);
out.println(FileName);
out.println(pingp);
out.println("<font size=4 color=blue>谢谢您的上传,正在处理您的上传信息,稍后会自动再次进入上传页面........</font><meta http-equiv='refresh' content='2;url=cpupload.jsp'>");%>

小弟都折腾半天了,还不知道那里出错了?
谢谢大家!
...全文
127 点赞 收藏 10
写回复
10 条回复

还没有回复,快来抢沙发~

发动态
发帖子
Web 开发
创建于2007-09-28

5.2w+

社区成员

34.1w+

社区内容

Java Web 开发
社区公告
暂无公告