[英]Understanding web.xml
I am trying to create a dynamic web project using eclipse.This is the first time I am working on servlets and jsp. 我正在尝试使用eclipse创建动态Web项目。这是我第一次使用servlet和jsp。
I have created a page and it works fine. 我已经创建了一个页面,并且效果很好。 However I am not able to understand the web.xml page entirely.
但是,我无法完全理解web.xml页面。 As far as I have read and searched that <url-pattern> under <servlet-mapping> is used by the client to access your servlet.
据我阅读并搜索的内容, < servlet-mapping>下的<url-pattern>被客户端用来访问您的servlet。 However whatever I change my <url-pattern> to,it seems to only access the servlet through servlet class name.
但是,无论我将<url-pattern>更改为什么,似乎都只能通过servlet类名称访问servlet。
<display-name>CustomerManagment1</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>Welcome Page</servlet-name>
<servlet-class>WelcomePage</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Welcome Page</servlet-name>
<url-pattern>/welcomepage.jsp</url-pattern>
</servlet-mapping>
</web-app>
The browser complaints when I use http://host-name/CustomerManagment1/welcompage.jsp
当我使用
http://host-name/CustomerManagment1/welcompage.jsp
时,浏览器会抱怨
However if use this http://host-name/CustomerManagment1/WelcomePage
, it works fine. 但是,如果使用此
http://host-name/CustomerManagment1/WelcomePage
,则可以正常工作。 What am I missing here? 我在这里想念什么?
Have you written a JSP or a servlet? 您是否编写了JSP或servlet? I am a little bit confused If you are using a JSP, then the servlet tag should be like
我有点困惑,如果您使用的是JSP,则servlet标签应该像
<servlet>
<description></description>
<display-name>WelcomePage</display-name>
<servlet-name>WelcomePage</servlet-name>
<jsp-file>/WelcomePage.jsp</jsp-file>
</servlet>
If you are using servlet , then your tag is fine. 如果您正在使用servlet,那么您的标签就可以了。
In case of url-pattern, are you sure you have not written any annotation for the WelcomPage servlet class? 如果是url-pattern,您确定没有为WelcomPage servlet类编写任何注释吗? If you are using Tomcat 7 or any java EE 6 container, then creating a new servlet through eclipse will create a default @WebServlet annotation and add to the servlet as follows.
如果您使用的是Tomcat 7或任何Java EE 6容器,则通过eclipse创建新的servlet将创建默认的@WebServlet批注并按如下所示添加到servlet中。
@WebServlet("/WelcomePage")
public class WelcomePage extends HttpServlet {}
This means that your url pattern is being picked from here. 这表示您的网址格式是从这里选取的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.