有没有设置 form 的 multipart 属性啊?
解决方案 »
- 问下关于javamail发送邮件图片问题~
- hibernate中关于实例化Configuration的问题
- 我的模板代码存在数据库中能否动态解析?
- 开始学习用jsp做论坛,希望哪位朋友能发一个论坛的源代码给我学习
- 遇到个问题,大家帮个忙-result 'null' not found
- hibernate batch-size问题求助
- 关于Egothor的问题
- 请教:有关JSP不能正确运行的问题
- 求《Rational rose2002 由入门到精通》电子版
- 如何得到当前web应用名称?请帮忙
- 高手请进!!!~~~~~~~这个代码有点问题,哪儿错了,怎么修改?
- 谁知道哪里有在JB下面支持鼠标滚轮的插件!不胜感激!!!!!!!!!!!
http://www.csdn.net/Develop/read_article.asp?id=18987
没有错误
就是取不出文件?????????????
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link href="css/default.css" rel="stylesheet" type="text/css">
</head>
<script language="javascript">
function check_submit(form) {
if (form.hasPic.value == 1 && form.pic.value == "") {
alert("请输入档案");
return false;
} return true;
}
</script><body bgcolor="#189ECE" text="#000000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" >
<a name="top"></a>
<form name="myform" action="file_save.jsp" ENCTYPE="multipart/form-data" method="post" onsubmit="return check_submit(this)">
<input type="hidden" name="news_id" value="<%=request.getParameter("news_id")%>">
<input type="hidden" name="hasPic" value="1">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<br>
<table width="100%" border="0" cellspacing="0" cellpadding="5">
<tr>
<td align="right" valign="top">图片上传</td>
<td><input type="file" name="pic">(档案的大小不能超过10k)</td>
</tr>
<tr align="center">
<td colspan="2"> <input type="submit" name="Submit" value="确定上传">
<input type="button" value="不加图片" onclick="document.myform.hasPic.value = 0; document.myform.submit()">
</td>
</tr>
</table>
<p> </p>
<!-- InstanceEndEditable --></td>
</tr>
</table></td>
<td bgcolor="#FFFFFF"> </td>
</tr>
</table>
</form>
<p> </p></body>
<!-- InstanceEnd --></html>
保存文件的页面:
<%-- *********************************** page directive ********************************** --%><%@ page import="java.util.Date" %>
<%@ page import="com.jspsmart.upload.*" %>
<%@ page import="java.io.File" %>
<%-- ************************************************************************************* --%>
<jsp:useBean id="mySmartUpload" scope="page" class="com.jspsmart.upload.SmartUpload" />
<%
// upload the image file from user's computer
mySmartUpload.initialize(pageContext);
mySmartUpload.upload();
int fileSize = mySmartUpload.getSize();
com.jspsmart.upload.Request jspRequest = mySmartUpload.getRequest();
%>
<form name="myform" action="generate_news.jsp" method="post">
<input type="hidden" name="news_id" value="<%=jspRequest.getParameter("news_id")%>">
<input type="hidden" name="pic" value="">
</form>
<%
if(fileSize > 15360) {
// file size greater than expected
%>
<script language="javascript">
alert("抱歉!文件超过15k");
document.myform.action = "前一页面.jsp";
document.myform.submit();
</script>
<%
} else if(mySmartUpload.getFiles().getCount() > 0) {
// save it to the disk and get the file name that it is saved as
int count = mySmartUpload.save("tmp");
com.jspsmart.upload.File tmpFile = mySmartUpload.getFiles().getFile(0);
String fileName = tmpFile.getFileName();
String ext = tmpFile.getFileExt();
java.io.File oldFile = new java.io.File("tmp/" + fileName);
String path = oldFile.getAbsolutePath();
path = path.substring(0, path.indexOf("/tmp"));
Process proc = Runtime.getRuntime().exec("mv " + application.getInitParameter("HOMEPATH") + "tmp/" + fileName + " " + application.getInitParameter("HOMEPATH") + "generated_pages/images/news_" + jspRequest.getParameter("news_id") + "." + ext);
%>
<script language="javascript">
document.myform.pic.value = "<%=(jspRequest.getParameter("news_id") + "." + ext)%>";
document.myform.submit();
</script>
<%
} else {
%>
<script language="javascript">
document.myform.submit();
</script>
<%
}
%>