登陆功能实现_Servlet开发规则

登陆功能实现_Servlet开发规则

处理登陆请求web.xml配置

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns="http://xmlns.jcp.org/xml/ns/javaee"
	xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
	id="WebApp_ID" version="4.0">
	<!-- 配置servlet: 配置LoginServlet与请处理请求的映射 -->
	<servlet>
		<servlet-name>loginServlet</servlet-name>
		<servlet-class>com.xiaowang.login.servlet.LoginServlet</servlet-class>
	</servlet>
	<servlet-mapping>
		<servlet-name>loginServlet</servlet-name>
	<!-- 客戶端的登陆请求: http://locallost:8080/web01/login-->
		<url-pattern>/login</url-pattern>
	</servlet-mapping>

</web-app>

LoginServlet

package com.xiaowang.login.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class LoginServlet  extends HttpServlet{
	/**
	 * 常用方法:doGet  doPost service
	 * doGet:处理客户端get方式的请求
	 * doPost:处理客户端Post方式的请求
	 * service:根据客户端的请求方式去调用对应的doGet、doPost方法
	 */
	
	//要么重写service,要么重写doGet  doPost方法
	
	@Override
	protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		super.service(req, resp);
	}
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
	 doPost(req,resp);
	}
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
	
		System.out.println("登陆请求过来了............");
		
	}
	
	
	
	
	
	
	
}