ScA*_*er2 52
这是一个简单的例子.我对html或servlet并不感兴趣,但你应该明白这个想法.
我希望这能够帮到你.
<html>
<body>
<form method="post" action="/myServlet">
<input type="text" name="username" />
<input type="password" name="password" />
<input type="submit" />
</form>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
现在为Servlet
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class MyServlet extends HttpServlet {
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
String userName = request.getParameter("username");
String password = request.getParameter("password");
....
....
}
}
Run Code Online (Sandbox Code Playgroud)
Rya*_*arn 49
您的HttpServletRequest对象有一个getParameter(String paramName)可用于获取参数值的方法. http://java.sun.com/javaee/5/docs/api/javax/servlet/ServletRequest.html#getParameter(java.lang.String)
McD*_*ell 23
POST变量应该可以通过请求对象访问:HttpRequest.getParameterMap().例外情况是表单是否发送多部分MIME数据(FORM具有enctype ="multipart/form-data").在这种情况下,您需要使用MIME解析器解析字节流.您可以编写自己的或使用现有的Apache Commons File Upload API.
| 归档时间: |
|
| 查看次数: |
122721 次 |
| 最近记录: |