java 如何为多个servlet修改web.xml
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/43559372/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 07:32:30 来源:igfitidea点击:
how to modify web.xml for multiple servlet
提问by borderwing
I just get confused about how to modify web.xml for multiple servlet. I got three servlet to handle three different jsp, but now only one servlet is effective.
我只是对如何修改多个 servlet 的 web.xml 感到困惑。我得到了三个 servlet 来处理三个不同的 jsp,但现在只有一个 servlet 有效。
回答by Orestis Pantazos
You should declare and define the classes/servlets inside the web.xml file like this:
您应该像这样在 web.xml 文件中声明和定义类/servlet:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" 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_3_0.xsd">
<servlet>
<servlet-name>LoginForm</servlet-name>
<servlet-class>com.project.system.LoginForm</servlet-class>
</servlet>
<servlet>
<servlet-name>RegisterForm</servlet-name>
<servlet-class>com.project.system.RegisterForm</servlet-class>
</servlet>
<servlet>
<servlet-name>UserController</servlet-name>
<servlet-class>com.project.controller.UserController</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>LoginForm</servlet-name>
<url-pattern>/LoginForm</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>RegisterForm</servlet-name>
<url-pattern>/RegisterForm</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>UserController</servlet-name>
<url-pattern>/UserController</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
</web-app>