I am using Eclipse Java-EE and I'm trying to make a servlet from there. However, I see a problem with mapping url-pattern in web.xml, the tomcat server wont initialise when the value inside the url-mapping is not the same as the project name? Is there a way I can assign different url-mapping value apart开发者_如何学Python for the project name? Thanks.
for example your servlet definition is as below
<!-- Define the servlet -->
<servlet>
<servlet-name>yourServlet</servlet-name>
<servlet-class>com.YourServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>yourServlet</servlet-name>
<url-pattern>/servlet</url-pattern>
</servlet-mapping>
Say, your application root context is "webapplication" and your server is running on localhost,port 8080. then you can access above servlet http://localhost:8080/webapplication/servlet
if you are asking about Web Context root (webapplication in above example) then you can also change it. in eclipse, right click your project->properties ->
Web Project Setting and change name of your appplication in Context Root field.
精彩评论