Servlet之login
来源:互联网 发布:淘宝助理上传宝贝 编辑:程序博客网 时间:2024/05/18 01:32
<?xml version="1.0" encoding="UTF-8"?><web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"> <servlet> <description>This is the description of my J2EE component</description> <display-name>This is the display name of my J2EE component</display-name> <servlet-name>UserServlet</servlet-name> <servlet-class>servlet.UserServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>UserServlet</servlet-name> <url-pattern>/servlet/UserServlet</url-pattern> </servlet-mapping></web-app>
<%@ page language="java" import="java.util.*" contentType="text/html; charset=utf-8"%><%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html> <head> <base href="<%=basePath%>"> <title>My JSP 'login.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"><meta http-equiv="cache-control" content="no-cache"><meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"><meta http-equiv="description" content="This is my page"><!--<link rel="stylesheet" type="text/css" href="styles.css">--> </head> <body> <form action="servlet/UserServlet" name="loginForm" method="post"> <table> <tr> <td>用户名:</td> <td><input type="text" name="username"/></td> </tr> <tr> <td>密码:</td> <td><input type="password" name="password"/></td> </tr> <tr> <td><input type="submit" value="登陆"/></td> </tr> </table> </form> </body></html>
package servlet;import java.io.IOException;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import com.po.Users;public class UserServlet extends HttpServlet {/** * Constructor of the object. */public UserServlet() {super();}/** * Destruction of the servlet. <br> */public void destroy() {super.destroy(); // Just puts "destroy" string in log// Put your code here}/** * The doGet method of the servlet. <br> * * This method is called when a form has its tag value method equals to get. * * @param request the request send by the client to the server * @param response the response send by the server to the client * @throws ServletException if an error occurred * @throws IOException if an error occurred */public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {doPost(request, response);}/** * The doPost method of the servlet. <br> * * This method is called when a form has its tag value method equals to post. * * @param request the request send by the client to the server * @param response the response send by the server to the client * @throws ServletException if an error occurred * @throws IOException if an error occurred */public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {Users user = new Users();String username = request.getParameter("username");String password = request.getParameter("password");user.setUsername(username);user.setPassword(password);request.getSession().setAttribute("loginUser", user);if("admin".equals(username) && "admin".equals(password)){response.sendRedirect("../loginSuccess.jsp");}else{response.sendRedirect("../loginFailure.jsp");}}/** * Initialization of the servlet. <br> * * @throws ServletException if an error occurs */public void init() throws ServletException {// Put your code here}}
package com.po;public class Users {private String username;private String password;public Users(){}public String getUsername() {return username;}public void setUsername(String username) {this.username = username;}public String getPassword() {return password;}public void setPassword(String password) {this.password = password;}}
<%@ page language="java" import="java.util.*" contentType="text/html; charset=utf-8"%><%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html> <head> <base href="<%=basePath%>"> <title>My JSP 'login.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"><meta http-equiv="cache-control" content="no-cache"><meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"><meta http-equiv="description" content="This is my page"><!--<link rel="stylesheet" type="text/css" href="styles.css">--> </head> <body> <% String loginUser = ""; loginUser = session.getAttribute("loginUser").toString(); %> <h1>欢迎<%=loginUser %>登陆</h1> </body></html>
<%@ page language="java" import="java.util.*" contentType="text/html; charset=utf-8"%><%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html> <head> <base href="<%=basePath%>"> <title>My JSP 'login.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"><meta http-equiv="cache-control" content="no-cache"><meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"><meta http-equiv="description" content="This is my page"><!--<link rel="stylesheet" type="text/css" href="styles.css">--> </head> <body> <h1>用户名或者密码错误,请重新登陆</h1><br/> <a href="login.jsp">返回登陆</a> </body></html>
0 0
- Servlet之login
- LOGIN(之四)
- login(之五)
- SMGP协议之Login
- docker命令之login
- Openstack --- Horizon之login
- pwnable之simple login
- jsp登陆校验演示,servlet,login,success
- Struts2学习之Login源码
- login-config之auth-method
- Android入门之login设计
- linux命令之login命令
- linux常用命令之login命令
- angularjs之login登录页面
- login
- Login
- Login
- login
- onvif学习2-soap介绍以及gsoap使用
- 数据同步相关专利
- svn的配置和使用
- 机试算法讲解: 第46题 深度优先搜索之能否逃出魔掌
- Linux socket编程(三) 简单的多线程聊天室
- Servlet之login
- hdu 2037
- 深入理解Hadoop集群和网络
- Foj 1075 分解素因子
- 面向对象_封装
- 机试算法讲解:第47题 递推之N阶楼梯如何上楼
- TCP/IP学习笔记(一) .
- 修改linux主机名
- C语言深度解剖——读书笔记-2、关键字