java - How to properly map a servlet -
i have mapped servlet this
<?xml version="1.0" encoding="utf-8"?> <web-app version="2.5" 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"> <servlet> <servlet-name>s1</servlet-name> <servlet-class>firstservlet</servlet-class> </servlet> <servlet> <servlet-name>s2</servlet-name> <servlet-class>secondservlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>s1</servlet-name> <url-pattern>/servlet1/*</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>s2</servlet-name> <url-pattern>/servlet2/*</url-pattern> </servlet-mapping> <session-config> <session-timeout> 30 </session-timeout> </session-config> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> </web-app>
thing whenever write in url
case1 : localhost:2040/sampleerror/servlet2/name
case2 : localhost:2040/sampleerror/servlet2/name/surname
it goes same servlet know haven't done url mapping please suggest me modification in case 2 should show 404 error resources not available
actually application name "sampleerror" "name" , "surname" in url dynamic 1 mean can give there insead of "name" can give name or
change web.xml mapping this:
<servlet-mapping> <servlet-name>s2</servlet-name> <url-pattern>/servlet2/name</url-pattern> </servlet-mapping>
the pattern /servlet2/*
means url containing servlet2
string in uri mapped secondservlet
. thats reason both /name
, /name/surname
being handled secondservlet
Comments
Post a Comment