how can i change my url-pattern in servlet mapping without facing 404

1.6k views Asked by At
<servlet>
    <servlet-name>UploadServlet</servlet-name>
    <servlet-class>com.UploadServlet</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>UploadServlet</servlet-name>
    <url-pattern>/go</url-pattern>
</servlet-mapping>
 <session-config>
    <session-timeout>
        30
    </session-timeout>
</session-config>

when I use /go as url-pattern ,it is working . when I alter it to some other name it is not,like/servletgo. HOw can I alter it .xml file?

1

There are 1 answers

0
raj On BEST ANSWER

I got the answer..

whatever the 'action' we wrote in html file is to be write in url-pattern which is under .xml file.

for example:

my html code:

<html>
   <body>  
<form action="welcome" method="post" enctype="multipart/form-data">  
Select File:<input type="file" name="fname"/><br/>  
<input type="submit" value="upload"/>  
</form>  
</body>  
</html>  
</html>

and my servlet code:

<servlet>
    <servlet-name>UploadServlet</servlet-name>
    <servlet-class>com.UploadServlet</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>UploadServlet</servlet-name>
    <url-pattern>/welcome</url-pattern>  //we have to use same pattern what we noted in html action.If we change the action name in html,then only we can change the url- pattern.
</servlet-mapping>
 <session-config>
    <session-timeout>
        30
    </session-timeout>
</session-config>