servlet @WebServlet注释的用法
Posted 醉生梦死_0423
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了servlet @WebServlet注释的用法相关的知识,希望对你有一定的参考价值。
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注释的用法的主要内容,如果未能解决你的问题,请参考以下文章
哪个更适合专业使用(web.xml(部署描述符)或@WebServlet注释?[关闭]
关于解决Server Tomcat v9.0 Server at localhost failed to start的问题
eclipse运行web,tomcat报错Server Tomcat v9.0 Server at localhost failed to start