servlet如何得到表单传递过来的信息
我有一个login.jsp页面,当中有一个表单。其中form的action属性为updateServlet,即servlet的名字。我的servlet代码如下:
public class updateServlet extends HttpServlet {
private static final String CONTENT_TYPE = "text/html; charset=GBK ";
//Initialize global variables
public void init() throws
ServletException {
}
//Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException,
IOException {
response.setContentType(CONTENT_TYPE);
String sLoginName = request.getParameter( "loginName ");
PrintWriter out = response.getWriter();
out.println( " <html> ");
out.println( " <head> <title> updateServlet </title> </head> ");
out.println( " <body bgcolor=\ "#ffffff\ "> ");
out.println( " <p> 登陆名是: " + sLoginName + " </p> ");
out.println( " </body> ");
out.println( " </html> ");
out.close();
}
我仅仅是想在servlet当中得到jsp页面当中的用户名。但是在执行的时候却显示
Help viewer error
URL: Unable to open location: Document not found on serve
这样的错误,我是一个初学者。请高手帮帮忙阿。
------解决方案--------------------用String name=request.getParameter( "属性名 ");得到你表单中提交的数据
------解决方案--------------------package com.e266.servletCode;
import
java.io.IOException;
import java.io.PrintWriter;
import
javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class welcomeOne extends HttpServlet {
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType( "text/html ");
String name=request.getParameter( "name ");
String sex=request.getParameter( "sex ");
String path= "/pages/welcomeOne.jsp ";