1

Hi I am new here and have an issue in JSP. In Eclipse, I created a Dynamic Web Project. I right clicked on WEB-INF folder to create a new folder named jsp. In the folder jsp, I created a new jsp file named "yes.jsp". The jsp file is a simple jsp file.

This is yes.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Yes</title>
</head>
<body>
Yes
</body>
</html>

Now, in my web.xml, when I want to run yes.jsp, I wrote my web.xml as below

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>test</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
    <welcome-file>WEB-INF/jsp/yes.jsp</welcome-file>
  </welcome-file-list>
</web-app>

In the welcome-file I have tried various other alternatives like jsp/yes.jsp, /jsp/yes.jsp, jsp\yes.jsp

But every time I run this, I get the response like

HTTP Status 404 -


type Status report

message

description The requested resource is not available.


Apache Tomcat/7.0.55

Please help me to understand where I am going wrong.

Thank you!

Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360
Ori
  • 55
  • 1
  • 1
  • 9

2 Answers2

3

You should put your jsp files outside of WEB-INF folder but beside of that. Folder Structure:

root/

  /WEB-INF

  /META-INF

  /jsp/yes.jsp
Super Hornet
  • 2,839
  • 5
  • 27
  • 55
  • I generally create jsp files under WebContent. But in my project, they have set the folder structure like this. And now I have to conform to the same. I have never tried this folder structure before. This was the first time and I found out I cant even run a simple jsp file. That thought was kinda disturbing, mate. Thus, wanna know how I can access a jsp file that way, if at all it can be done. Thanks again for the answer though, @SuperHornet – Ori Aug 29 '15 at 15:13
  • This was the first answer given. – Tim Biegeleisen Aug 29 '15 at 15:35
0

You can not access WEB-INF folder directly. That's why you are getting this error. You can achieve this by putting name of servlet in welcome file tag. And in that servlet, write the code to dispatch the request object to jsp page present in WEB-INF folder.

Let me know if you have any doubt.

Note: Don't forget to do mapping of servlet in web.XML file.

Zishan Mohsin
  • 828
  • 1
  • 9
  • 22
  • Thanks Mohsin. But the thing is, what if I dont want to use any servlet? If I use a servlet, I understand the mapping can be done. But I directly want to access a jsp page which is inside a folder under WEB-INF. Like, if I am creating a jsp page straight under WebContent, we can directly run that by mentioning it in the web.xml welcome-file-list. I want to know if there is a similar simple way to access a jsp file which i create in a folder under WEB-INF. – Ori Aug 29 '15 at 15:09
  • You can't access any file present in WEB-INF folder directly from browser. While you can use my above mentioned way, its too simple. – Zishan Mohsin Aug 29 '15 at 15:18