0

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
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
user1050619
  • 19,822
  • 85
  • 237
  • 413
  • This is not a duplicate..That ticket talks about the response object this thread talks about the URL mapping. – user1050619 Jan 01 '15 at 21:22
  • Basically, it's in conflict with the default servlet that serves the static content. – Paul Samsotha Jan 02 '15 at 04:27
  • Thanks..Can you elaborate more on this or provide me a link that I can refer too? – user1050619 Jan 02 '15 at 04:32
  • 1
    There is a default servlet that serve up static content, like your html pages. That is mapped to `/*`. You have defined a Jersey servlet with the same mapping. The default servlet wins. It will not redirect to the Jersey Servlet. So if the default servlet can't find `file/upload` (which it won't as it's not designed to find Jersey resources), it will send you a Not Found – Paul Samsotha Jan 02 '15 at 04:41

0 Answers0