9

I created a JSP file.

sample.jsp

<%@ page pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
  <head>
    <title>Insert title here</title>
  </head>
  <body>
    This is jsp program
  </body>
</html>

I placed it here in the samplejsp project.

samplejsp
 `-- WebContent
      `-- WEB-INF
           `-- sample.jsp

I opened it on the following URL.

http://localhost:8080/samplejsp/sample.jsp

But it shows the following error in browser.

404 ERROR

The requested resource (/sample.jsp) is not available.

2
  • sorry,I resolve my mistake today omwards
    – user246160
    Mar 5, 2010 at 10:59
  • 7 days passed and you haven't accepted nothing since...
    – Axarydax
    Mar 13, 2010 at 12:38

4 Answers 4

8

404 simply means "Not Found".

Either the URL is wrong (note: case sensitive!), or the resource is not there where you think it is.

Just verify the URL and/or verify if the resource is there where you'd expect it to be. You placed sample.jsp in /WEB-INF folder. This way it is not publicly accessible without calling through a front controller servlet.

Put it outside /WEB-INF.

samplejsp
 `-- WebContent
      |-- WEB-INF
      `-- sample.jsp

If you want to keep it in /WEB-INF, then you need to create a front controller servlet which forwards to it in doGet() method as below.

request.getRequestDispatcher("/WEB-INF/sample.jsp").forward(request, response);

Finally "open" the JSP by just calling servlet's actual URL instead of JSP's fictive URL.

See also:

4
  • ya i checked but it shows the above error ,Is there any error in the program
    – user246160
    Mar 5, 2010 at 11:17
  • Yes, either the URL is wrong, or the resource is actually not there. The error message does not lie.
    – BalusC
    Mar 5, 2010 at 11:43
  • ok,i accept the error message not lie,Ya error occurred in URL i understood that also,I selected the the jsp file and copied the URL from Properties,Then why it shows the error,How to solve this?
    – user246160
    Mar 5, 2010 at 11:48
  • Hint: the URL should be an URL, not a disk file system path. If sample.html is at http://localhost:8080/samplejsp/sample.html then the sample.jsp is obviously at http://localhost:8080/samplejsp/sample.jsp. Thus the <form action> should be http://localhost:8080/samplejsp/sample.jsp or better just sample.jsp. In your case, this should do: <form action="sample.jsp">.
    – BalusC
    Mar 5, 2010 at 12:11
1

It's mostly related to your directory structure or packaging.
Can you please add your directory structure?

Similar to below -

src 
|-html\
|-jsp\

Perhaps this should do it

<form action="sample.jsp" method=get>
      <input type =submit value="submit">
</form>

Edit - WEB-INF does not allow direct access to JSP.

2
  • Quick fix - Move the HTML and JSP file from WEB-INF folder and run.
    – Padmarag
    Mar 5, 2010 at 11:49
  • I mean move both the files from WEB-INF to some other folder.
    – Padmarag
    Mar 5, 2010 at 12:30
0

In my spring boot web application with JSP it didn't worked until I have added this dependency

    <dependency>
        <groupId>org.apache.tomcat.embed</groupId>
        <artifactId>tomcat-embed-jasper</artifactId>
        <scope>provided</scope>
    </dependency>

even after configuring view resolver

spring.mvc.view.prefix: /WEB-INF/views/ 
spring.mvc.view.suffix: .jsp

If you find why this worked please comment.

1
  • 1
    tomcat-embed-jasper: provides support for .jsp file rendering. Apr 5, 2021 at 16:44
0

I had got this error- JSP file [/WEB-INF/viewshello.jsp] not found.

I have created the Jsp file hello in the view folder inside WEB-INF folder insted it can't able to find the resource.

Then I have deleted the previous "hello.jsp" file and created the new one at the same location.

And it works finally!! May be it will work in your case also..so try it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.