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

匿名 (未验证) 提交于 2019-12-03 01:23:02

问题:

I created a JSP file.

sample.jsp

          <span class="typ" bdsfid="169">Insert</span><span class="pln" bdsfid="170"> title here</span>     This is jsp program    

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.

回答1:

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:



回答2:

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

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



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!