码迷,mamicode.com
首页 > Web开发 > 详细

servlet @WebServlet注释的用法

时间:2018-11-10 14:57:17      阅读:282      评论:0      收藏:0      [点我收藏+]

标签:bsp   alt   todo   write   att   res   protect   参数   打印   

技术分享图片

package servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class GetInitParameterServlet
 */
@WebServlet(//此版块是从其他博主的文章学习过来的,侵删
             //Servlet的访问URL
             value="/servlet/GetInitParameterServlet",
             //Servlet的访问URL,可以使用数组的方式配置多个访问路径
             urlPatterns={"/servlet/GetInitParameterServlet"},//此方法和value的作用一样
             //Servlet的初始化参数
             initParams={
                     @WebInitParam(paramName="zsms",paramValue="醉生梦死")//在服务器初始化的时候会打印,因为调用Init方法
             },
             name="GetInitParameterServlet",//不填的话默认是类的路径
             description="处理用户登录的Servlet"
         )
public class GetInitParameterServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public GetInitParameterServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        response.getWriter().append("Served at: ").append(request.getContextPath());
    }

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        doGet(request, response);
    }

}

 

servlet @WebServlet注释的用法

标签:bsp   alt   todo   write   att   res   protect   参数   打印   

原文地址:https://www.cnblogs.com/lavender-pansy/p/9938824.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!