url not found for xml mapping in web.xml



I have a basic question on how the xml mapping and the controller works. I have given different scenarios where it works and where I expect it to work and not working.


Jersey controller-



@Path("/file")
public class UploadFileService {
@POST
@Path("/upload")
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response uploadFile(


html Form - index.jsp



<form action="file/upload" method="post" enctype="multipart/form-data">
<input type="input" name="username" placeholder="Enter Username"/>
<br><br>
<input type="input" name="password" placeholder="Enter Password"/>
<br><br><br>
<hr>
<p>
Select a file : <input type="file" name="file" size="45" />
</p>
<br>


<input type="submit" value="Upload It" />
</form>


URL Mapping in web.xml



<servlet-mapping>
<servlet-name>jersey-serlvet</servlet-name>
<url-pattern>/*/*</url-pattern>
</servlet-mapping>


Application Name:RESTFileUpload



http://localhost:8080/RESTFileUpload - index.jsp page is returned.

http://localhost:8080/RESTFileUpload/file/upload - Page not found 404.


but when I changed "file/upload" to "/rest/file/upload" the page is found



http://localhost:8080/RESTFileUpload/rest/file/upload


Question:-


Why the URL is not found when the form action is "file/upload" and url mapping is



<servlet-mapping>
<servlet-name>jersey-serlvet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>

http://localhost:8080/RESTFileUpload/file/upload - not found

No comments:

Post a Comment