最近看了通过smartupload怎么上传文件,虽然smartupload有很多局限性,已经不用了,但还是看一看。遇到了一个奇怪的问题。
html文件代码如下,文件名upload.html:
<html>
<head>
<title>upload.html</title>
</head>
<body>
<form action="smartupload.jsp" method="post" enctype="multipart/form-data">
新文件名称: <input type="text" name="uname"><br>
选择上传的文件:<input type="file" name="sf"><br>
<input type="submit" value="上传" />
</form>
</body>
</html>
jsp处理代码如下,文件名smartupload.jsp
<%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
<jsp:useBean id="smartupload" class="org.lxh.smart.SmartUpload"/>
<html>
<head>
<title>smartupload</title>
</head>
<body>
<%
request.setCharacterEncoding("GBK") ;
smartupload.initialize(pageContext) ; // 初始化上传
smartupload.upload() ; // 准备上传
String name = smartupload.getRequest().getParameter("uname") ;
smartupload.save("upload") ; // 保存文件
%>
<h1><%=name%></h1>
</body>
</html>
由于通过smartupload上传文件时,需要封装,因此不能直接通过request.getParameter("uname");取得参数值,只能通过smartupload.getRequest().getParameter("uname") ;取得页面提交过来的表单元素值,但按照上述代码,死活就是取不能uname的值,代码没一点问题,无奈之下将
upload.html的后缀名改成htm后,好使了,特别惊讶,因为html与htm的后缀,通过MIME解析都是相同的,不知道为什么?大家有没有遇到过这种情况?