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);
}
}
<%@ 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>
效果图:
原文地址:http://blog.csdn.net/lpjishu/article/details/45645959