Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
421 views
in Technique[技术] by (71.8m points)

JSP in /WEB-INF returns "HTTP Status 404 The requested resource is not available"

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.

Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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:


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...