丝路之行zhengdong.blog.chinaunix.net
zhengdong1987
全部博文(101)
MySQL(2)
AVR(0)
Android_APP(7)
SNMP(15)
Servlet(7)
html(1)
Jsp(1)
WEB(0)
Java编程(15)
MVC(0)
Eclipse(0)
Spring(0)
Tomcat(1)
应用(29)
qt(0)
Linux驱动(6)
2012年(3)
2011年(60)
2010年(38)
ayyicdms
曾德标
zwsolive
shuixing
zhangjie
jchaodon
tekkaman
大鬼不动
sswqzx
浪花小雨
Bsolar
wenfei63
dahai071
HuangWJ_
mxj30708
zxcvbnm4
alex1028
zjc06181
分类: 系统运维
2010-11-22 08:53:10
package shark.zd.servlets;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 LoginServlet extends HttpServlet{ public void doPost(HttpServletRequest request, HttpServletResponse response) { String userName = request.getParameter("userName"); String userPassword = request.getParameter("userPassword"); if ("zd".equals(userName)&&"123".equals(userPassword)) { try { PrintWriter pw = response.getWriter(); pw.println("success"); pw.close(); } catch (IOException e) { e.printStackTrace(); } } else { try { response.sendRedirect("login.html"); } catch (IOException e) { // TODO: handle exception e.printStackTrace(); } } } }
HTML代码如下:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html> <head> <title>login.html</title> </head> <body> <form action="loginServlet" method="post"> <table> <tr> <td>用户名:</td> <td><input type="text" name="userName"/</td> </tr> <tr> <td>密码:</td> <td><input type="password" name="userPassword"/></td> </tr> <tr> <td><input type="submit" value="提交"/></td> <td><input type="reset" value="清空"/></td> </tr> </table> </form> </body></html>
web.xml代码如下:
<servlet> <servlet-name>LoginServlet</servlet-name> <servlet-class>shark.zd.servlets.LoginServlet</servlet-class></servlet><servlet-mapping> <servlet-name>LoginServlet</servlet-name> <url-pattern>/loginServlet</url-pattern></servlet-mapping>
上一篇:HttpServlet方法应用
下一篇:Snmp4j编程简介之一:Target
登录 注册