Servlet编程实例-servlet学习之旅(三)-LMLPHP

LoginServlet代码:

public class LoginServlet extends HttpServlet{

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        String name = req.getParameter("uName");
        String pswd = req.getParameter("uPswd");
        System.out.println("用户名:"+name);
        System.out.println("密码:"+pswd);
    }

}

Login.jsp的代码:

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>登陆界面</title>
</head>
<body>
    <form action="<%= request.getContextPath() %>/loginServlet" method="get">
        userName:<input type="text" name="uname" /><br/>
        userPwsd:<input type="password" name="upwsd" /><br/>
        <input type="submit" value="Login"/>
        <input type="reset" value="Reset"/>
    </form>
</body>
</html>

配置文件

 <servlet>
    <servlet-name>LoginServlet</servlet-name>
    <servlet-class>liu.peng.servlet.LoginServlet</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>LoginServlet</servlet-name>
    <url-pattern>/loginServlet</url-pattern>
  </servlet-mapping>

效果图:

Servlet编程实例-servlet学习之旅(三)-LMLPHP

04-28 14:35