IntelliJ IDEA 14.03 运行servlet前怎样设置web.xml

2025-03-26 17:05:07
推荐回答(2个)
回答1:

web.xml


         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
         version="3.1">
    
        Servlet
        Servlet.MyServlet //中的内容是固定的,必须是"Servlet所在包的名称.Servlet类的名称"
    

    
        Servlet
        /Servlet/MyServlet
    

新建的四个标签中servlet-class标签的内容是固定的,不能随意修改

servlet-name标签中的内容自定,但两个servlet-name标签中的内容必须相同

url-pattern标签中的内容自定,如例子中url-pattern为 /Servlet/MyServlet ,tomcat端口(默认)为8080,

则启动项目后,在浏览器中输入,即可访问到servlet所定义的页面

回答2:


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_2_5.xsd">


This is the description of my J2EE component
This is the display name of my J2EE component
LoginServlet
LoginServlet



LoginServlet
/LoginServlet


index.jsp