package com.atguigu.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;
/**
* 處理登錄請求的Servlet
*
* Servlet是sun公司制定的標準,Tomcat(web應用服務器、servlet容器)實作了標準.
*
* HttpServlet;
*/
public class LoginServlet extends HttpServlet{
/**
* 常用的方法: doGet doPost service
* doGet:處理客戶端的get方式的請求
*
* doPost:處理客戶端的post方式的請求
*
* service:根據具體請求方式去呼叫對應的doGet、doPost 方法
*/
@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("登錄請求過來了.....");
}
}
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<!-- 配置LoginServlet:配置LoginServlet與 處理請求的映射.
客戶端請求匹配的程序:
與<servlet-mapping>中的<url-pattern>進行匹配,匹配到以后,再找到<servlet-mapping>
中的<servlet-name>的值,再拿上該值到<servlet>節點中匹配相同的<servlet-name>,進而找到
<servlet-class>
Tomcat通過反射的方式創建LoginServlet的實體,根據具體的請求方式呼叫對應的doGet或者是doPost方法.
-->
<servlet>
<servlet-name>loginServlet</servlet-name>
<servlet-class>com.atguigu.login.servlet.LoginServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>loginServlet</servlet-name>
<url-pattern>/login</url-pattern>
</servlet-mapping>
</web-app>




轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/167013.html
標籤:Eclipse
