你测试一下下面的一个小程序,看能不能用: <html> <body><h1>Please tell me about yourself</h1><form action="SimpleFormHandler.jsp" method="POST"> Name: <input type="text" name="firstName"> <input type="text" name="lastName"><br> Sex: <input type="radio" checked name="sex" value="male">Male <input type="radio" name="sex" value="female">Female <p> What Java primitive type best describes your personality: <select name="javaType"> <option value="boolean">boolean</option> <option value="byte">byte</option> <option value="char" selected>char</option> <option value="double">double</option> <option value="float">float</option> <option value="int">int</option> <option value="long">long</option> </select> <br> <input type="submit"> </form> </body> </html> SimpleFormHandler.jsp 文件为: <html> <body><%// Grab the variables from the form. String firstName = request.getParameter("firstName"); String lastName = request.getParameter("lastName"); String sex = request.getParameter("sex"); String javaType = request.getParameter("javaType"); %> <%-- Print out the variables. --%> <h1>Hello, <%=firstName%> <%=lastName%>!</h1> I see that you are <%=sex%>. You know, you remind me of a <%=javaType%> variable I once knew.</body> </html>
String name=request.getParameter("id");这是什么问题?
这样也就可以直接得到file对象你这样测试一下看行不:
String pictureName=request.getAttribute("image12").getName();
//发现这句是取不到值的!
//out.print(pictureName);这句用于测试,注释掉以下语句,用这句输出是null
File picfile=new File(pictureName);//我经过测试,出现错误的是这里!我也没试过,你先试试吧
An error occurred at line: 8 in the jsp file: /5.jspGenerated servlet error:
[javac] Compiling 1 source fileC:\Program Files\Apache Software Foundation\Tomcat 5.0\work\Catalina\localhost\test\org\apache\jsp\_5_jsp.java:61: cannot resolve symbol
symbol : method getName ()
location: class java.lang.Object
String pictureName=request.getAttribute("image12").getName();
^
1 error
我用resin和tomcat都试过,还是不行!真晕!!!
String name=request.getParameter("id");是不是服务器有问题?
<html>
<body><h1>Please tell me about yourself</h1><form action="SimpleFormHandler.jsp" method="POST">
Name:
<input type="text" name="firstName">
<input type="text" name="lastName"><br>
Sex:
<input type="radio" checked name="sex" value="male">Male
<input type="radio" name="sex" value="female">Female
<p>
What Java primitive type best describes your personality:
<select name="javaType">
<option value="boolean">boolean</option>
<option value="byte">byte</option>
<option value="char" selected>char</option>
<option value="double">double</option>
<option value="float">float</option>
<option value="int">int</option>
<option value="long">long</option>
</select>
<br>
<input type="submit">
</form>
</body>
</html>
SimpleFormHandler.jsp 文件为:
<html>
<body><%// Grab the variables from the form.
String firstName = request.getParameter("firstName");
String lastName = request.getParameter("lastName");
String sex = request.getParameter("sex");
String javaType = request.getParameter("javaType");
%>
<%-- Print out the variables. --%>
<h1>Hello, <%=firstName%> <%=lastName%>!</h1>
I see that you are <%=sex%>. You know, you remind me of a
<%=javaType%> variable I once knew.</body>
</html>
除去句就可以了,这句不是标明确规定form可以进行文件操作的吗?
之前我没有用这句,会有个错误,说什么SQLsever自动分割数据!不能成功,现在我去掉它又行了!
我现在又发现,原来我这种方法,只能在本机上解决问题,变为我这样做已经没什么意义了.
有没有更好的上传到数据库的方法了?
不用jspsmartupload!!!
http://community.csdn.net/Expert/FAQ/FAQ_Index.asp?id=33247
例如aaa.jsp?custom=111&user=12
在aaa.jsp就用getParameter()来获取参数
例如aaa.jsp?custom=111&user=12
在aaa.jsp就用getParameter()来获取参数