现在有两个文件upload.jsp,action_upload.jsp。
调用upload.jsp可以上传文件成功。
我现在有一个文件news.jsp,本来里面是没有文件上传的,现在想加上去,但是不知道怎么加?
注:news.jsp如下:
<form action="savenews.jsp?" method="POST" onSubmit="return check(this)" name="frmnews">
<table cellpadding=0 cellspacing=0 border=0 width="95%" cellspacing="0">
<tr><td width="100%">
<table cellpadding=3 cellspacing=1 border=0 width=100%>
<tr><td width="20%"><b>用户名</b></td>
<td width="86%"><input name="userName" value=""</td>
</tr>
<tr><td width="14%"><b>密码</b></td>
<td width="86%"><input name="userPassword" type="password" value="“</td>
</tr>
<tr><input type=Submit value="发 表" name=Submit> </tr>
</table>
</td>
</tr>
</table>
</form>upload.jsp为
<%@ page contentType="text/html;charset=GBK" %>
<html>
<head>
<title>文件上传</title>
<meta http-equiv="Content-Type" content="text/html; charset=gbk">
</head>
<body>
<FORM METHOD="POST" ACTION="action_upload.jsp" ENCTYPE="multipart/form-data">
<p>请选择要上传的文件
<p><input type="FILE" name="FILE1" size="30">
<p><input type="submit" value="上传">
</FORM>
</body>
</html>action_upload.jsp为
<%@ page contentType="text/html;charset=GBK" %>
<html>
<head>
<title>文件上传处理页面</title>
<meta http-equiv="Content-Type" content="text/html; charset=gbk">
</head><body>
<jsp:useBean id="su" scope="page" class="com.jspsmart.upload.SmartUpload" />
<%
su.initialize(pageContext);
su.upload();
int count = su.save("/pic", su.SAVE_VIRTUAL);
out.println(count+"个文件上传成功!<br>");
for (int i=0;i<su.getFiles().getCount();i++)
{
com.jspsmart.upload.File file = su.getFiles().getFile(i);
if (file.isMissing()) continue;
out.println("<br>文件名:" + file.getFileName()+" 长度:"+file.getSize());
}
%>
</body>
</html>
问题在于:我想在密码后面加上文件上传,但news.jsp里面已经是有<form action="savenews.jsp?" method="POST" onSubmit="return check(this)" name="frmnews">这句话了,我该怎么添加upload.jsp进去呀?
调用upload.jsp可以上传文件成功。
我现在有一个文件news.jsp,本来里面是没有文件上传的,现在想加上去,但是不知道怎么加?
注:news.jsp如下:
<form action="savenews.jsp?" method="POST" onSubmit="return check(this)" name="frmnews">
<table cellpadding=0 cellspacing=0 border=0 width="95%" cellspacing="0">
<tr><td width="100%">
<table cellpadding=3 cellspacing=1 border=0 width=100%>
<tr><td width="20%"><b>用户名</b></td>
<td width="86%"><input name="userName" value=""</td>
</tr>
<tr><td width="14%"><b>密码</b></td>
<td width="86%"><input name="userPassword" type="password" value="“</td>
</tr>
<tr><input type=Submit value="发 表" name=Submit> </tr>
</table>
</td>
</tr>
</table>
</form>upload.jsp为
<%@ page contentType="text/html;charset=GBK" %>
<html>
<head>
<title>文件上传</title>
<meta http-equiv="Content-Type" content="text/html; charset=gbk">
</head>
<body>
<FORM METHOD="POST" ACTION="action_upload.jsp" ENCTYPE="multipart/form-data">
<p>请选择要上传的文件
<p><input type="FILE" name="FILE1" size="30">
<p><input type="submit" value="上传">
</FORM>
</body>
</html>action_upload.jsp为
<%@ page contentType="text/html;charset=GBK" %>
<html>
<head>
<title>文件上传处理页面</title>
<meta http-equiv="Content-Type" content="text/html; charset=gbk">
</head><body>
<jsp:useBean id="su" scope="page" class="com.jspsmart.upload.SmartUpload" />
<%
su.initialize(pageContext);
su.upload();
int count = su.save("/pic", su.SAVE_VIRTUAL);
out.println(count+"个文件上传成功!<br>");
for (int i=0;i<su.getFiles().getCount();i++)
{
com.jspsmart.upload.File file = su.getFiles().getFile(i);
if (file.isMissing()) continue;
out.println("<br>文件名:" + file.getFileName()+" 长度:"+file.getSize());
}
%>
</body>
</html>
问题在于:我想在密码后面加上文件上传,但news.jsp里面已经是有<form action="savenews.jsp?" method="POST" onSubmit="return check(this)" name="frmnews">这句话了,我该怎么添加upload.jsp进去呀?
<iframe name="up" frameborder="0" width="100%" height="24" scrolling="no" src="upload.jsp"></iframe>郁闷!!!
然后在action_upload.jsp里用
su.myUpload.getRequest().getParameter("userName");同时获取那些值给你个其他例子-----------------------------------------sample5.htm
<HTML>
<BODY BGCOLOR="white"><H1>jspSmartUpload : Sample 5</H1>
<HR><form METHOD="POST" ACTION="sample5.jsp" NAME="PW" ENCTYPE="multipart/form-data">
<table CELLSPACING="0" CELLPADDING="3" BORDER="1" WIDTH="474"><!-- FILE -->
<tr>
<td><small><font face="Verdana">Select a first file : </font></small></td>
<td><small><font face="Verdana"><input TYPE="file" name="FILE1"></font></small></td>
</tr> <tr>
<td><small><font face="Verdana">Select a second file : </font></small></td>
<td><small><font face="Verdana"><input TYPE="file" name="FILE2"></font></small></td>
</tr><!-- TEXT -->
<tr>
<td width="150"><div align="left"><p><small><font face="Verdana">Text : </font></small></td>
<td width="324"><small><font face="Verdana"><input TYPE="TEXT" name="myText" value=""><br></font></small></td>
</tr><!-- TEXTAREA -->
<tr>
<td width="150"><div align="left"><p><small><font face="Verdana">Text Area : </font></small></td>
<td width="324"><small><font face="Verdana"><textarea name="myTextArea" rows="4" value=""></textarea><br></font></small></td>
</tr><!-- PASSWORD -->
<tr>
<td><div align="left"><p><small><font face="Verdana">PassWord : </font></small></td>
<td><small><font face="Verdana"><input TYPE="PASSWORD" name="myPASSWORD" value=""><br></font></small></td>
</tr><!-- HIDDEN -->
<tr>
<td><div align="left"><p><small><font face="Verdana">Hidden : </font></small></td>
<td><small><font face="Verdana"><input TYPE="hidden" name="myHidden" value="hidden"><br></font></small></td>
</tr><!-- CHECKBOX -->
<tr>
<td><div align="left"><p><small><font face="Verdana">CheckBox : </font></small></td>
<td><small><font face="Verdana"><input TYPE="CHECKBOX" name="myCheckBox" value="Value 1">Value 1<br><input TYPE="CHECKBOX" name="myCheckBox" value="Value 2">Value 2<br><input TYPE="CHECKBOX" name="myCheckBox" value="Value 3">Value 3<br></font></small></td>
</tr><!-- RADIO -->
<tr>
<td><div align="left"><p><small><font face="Verdana">Radio : </font></small></td>
<td><small><font face="Verdana"><input TYPE="radio" name="radio" value="Value 1">Value 1<br><input TYPE="radio" name="radio" value="Value 2">Value 2<br><input TYPE="radio" name="radio" value="Value 3">Value 3<br></font></small></td>
</tr><!-- SELECT -->
<tr>
<td><div align="left"><p><small><font face="Verdana">Simple Select : </font></small></td>
<td><small><font face="Verdana"><SELECT name="mySimpleSelect" ><OPTION value="Value 1">Value 1</OPTION><OPTION value="Value 2">Value 2</OPTION><OPTION value="Value 3">Value 3</OPTION></SELECT><br></font></small></td>
</tr><!-- SELECT MULTIPLE -->
<tr>
<td><div align="left"><p><small><font face="Verdana">Multiple Select : </font></small></td>
<td><small><font face="Verdana"><SELECT multiple name="myMultSelect" ><OPTION value="Value 1">Value 1</OPTION><OPTION value="Value 2">Value 2</OPTION><OPTION value="Value 3">Value 3</OPTION></SELECT><br></font></small></td>
</tr><!-- SUBMIT -->
<tr>
<td colspan="2" width="474"><div align="center"><center><p><small><font face="Verdana"><input
TYPE="Submit"> </font></small></td>
</tr>
</table>
</form></BODY>
</HTML>-----------------------------------sample5.jsp
<%@ page language="java" import="com.jspsmart.upload.*"%>
<jsp:useBean id="myUpload" scope="page" class="com.jspsmart.upload.SmartUpload" /><HTML>
<BODY BGCOLOR="white"><H1>jspSmartUpload : Sample 5</H1>
<HR><% // Initialization
myUpload.initialize(pageContext); // Upload
myUpload.upload(); //
// Files
// out.println("<BR><STRONG>Display information about Files</STRONG><BR>"); out.println("Number of files = " + myUpload.getFiles().getCount() + "<BR>");
//out.println("Total size (bytes) = " + myUpload.getFiles().getSize() +"<BR>"); for (int i=0;i<myUpload.getFiles().getCount();i++){
out.print(myUpload.getFiles().getFile(i).getFieldName());
if (!myUpload.getFiles().getFile(i).isMissing())
out.print(" = " + myUpload.getFiles().getFile(i).getFileName() + " (" + myUpload.getFiles().getFile(i).getSize() + ")");
else
out.print(" = vide");
out.println("<BR>");
}
//
// Request
// out.println("<BR><BR><STRONG>Display information about Requests</STRONG><BR>");
// Retreive Requests' names
java.util.Enumeration e = myUpload.getRequest().getParameterNames(); // Retreive parameters
while (e.hasMoreElements()) { String key = (String)e.nextElement();
String[] values = myUpload.getRequest().getParameterValues(key);
// Browse the current parameter values
for(int i = 0; i < values.length; i++) {
out.print(key + " = ");
out.print(values[i] + "<BR>");
}
}%>
</BODY>
</HTML>
问题是在news.jsp里面已经有action一个jsp文件了。<form action="savenews.jsp?" method="POST" onSubmit="return check(this)" name="frmnews">
就是放在upload.jsp里的话,<FORM METHOD="POST" ACTION="action_upload.jsp" ENCTYPE="multipart/form-data">,upload.jsp也action一个jsp文件,而且是不一样的文件。另外,news.jsp里面的东西我不想改了,只想添加上传文件的代码。
news.jps里面N多代码的,我只是摘了一小部分出来。要改的话头都晕了。
再把action_upload.jsp上传问件的代码加到savenews.jsp里,在savenews.jsp读取其他字段就用
su.getRequest().getParameter("userName");这样子
<form action="savenews.jsp?" method="POST" ENCTYPE="multipart/form-data">
<table cellpadding=0 cellspacing=0 border=0 width="95%" cellspacing="0">
<tr><td width="100%">
<table cellpadding=3 cellspacing=1 border=0 width=100%>
<tr><td width="20%"><b>用户名</b></td>
<td width="86%"><input name="userName" value=""</td>
</tr>
<tr><td width="14%"><b>密码</b></td>
<td width="86%"><input name="userPassword" type="password" value=""></td>
</tr>
<tr>
<td colspan="2">
<p>请选择要上传的文件
<p><input type="FILE" name="FILE1" size="30"> <input type="button" value="上传" onClick="javascript:upload()">
</td>
</tr>
<tr><td><input type=Submit value="发 表" name=Submit></td> </tr>
</table>
</td>
</tr><script language="javascript">
function upload()
{
document.forms(0).action="action_upload.jsp";
document.forms(0).submit();
}
</script>
su.save("/pic", su.SAVE_VIRTUAL);这句话是放在action_upload.jsp目录的上一级目录的pic目录。
关于存放路径,如果是在存放在action_upload.jsp目录下的pic目录怎么办?
save语句怎么写?
我的方法是:
在news.jsp中加上一按钮,然后按了以后跳转到上传页面。
暂时只能这样做了。
谢谢各位,结贴给分了。