-2

I want to be able to access the jsp and html files in the WEB-INF folder of my web app which is running on a local glassfish server. How do I do this ? I know that it defeats the purpose of security. But, I want to try this.

Thanks.

sid smith
  • 483
  • 1
  • 6
  • 16
  • how do you want to access it ? – jmj Jul 11 '14 at 22:49
  • what you want to access? If it's a HTML/JSP then simply use `RequestDispatcher` Only application can access it. Content inside WEB-INF is not publically visible. – Braj Jul 11 '14 at 22:49
  • 1
    Use `servletContext.getResourceAsStream("/WEB-INF/myfile");`. [Read more...](http://stackoverflow.com/questions/1108434/howto-load-a-resource-from-web-inf-directory-of-a-web-archive) – Braj Jul 11 '14 at 22:53
  • @JigarJoshi - I want to do something which will let me access it by simply clicking on the url for the web app in glassfish/web server. That is it should open my index.jsp which is inside the WEB-INF folder. Is there some easy way to do this, like maybe changing some server config or web config for this ? I'd prefer not to do something that requires me to modify many jsp's and htmls. Thanks – sid smith Jul 11 '14 at 23:01
  • @Braj - can you please show me how ? thanks., – sid smith Jul 11 '14 at 23:02
  • 3
    you mean through web client (web browser) you want to access file residing in WEB-INF ? if so that is not possible – jmj Jul 11 '14 at 23:03
  • Have you read the link that I shared you. – Braj Jul 11 '14 at 23:03
  • @Braj - thanks. actually, I'd prefer to do it with some config of files like server.xml or web.xml instead of programmatically. Is that possible ? – sid smith Jul 11 '14 at 23:05
  • @JigarJoshi - that is what i want to do. – sid smith Jul 11 '14 at 23:06
  • WEB-INF is protected to be accessed from outside of the application's classpath. It's a security restriction. Otherwise, outside users could potentially gain access to your DB credentials, file system information, log files, etc. The restriction's there for a reason. Question is, why do you want to break this restriction? – blurfus Jul 11 '14 at 23:20
  • Read about request forwarding – jmj Jul 12 '14 at 00:47
  • The *whole point* of the WEB-INF folder is that it is inaccessible from the outside via URLs. Therefore it is utterly pointless to put .jsp and .html files into it. Your question doesn't make sense. – user207421 Jul 12 '14 at 03:16

2 Answers2

1

Use ServletContext.getResource("/WEB-INF/resource-file") to load the files in Java.

For direct access use some servlet mapping in your web.xml

<servlet>
  <servlet-name>myFoo</servlet-name>
  <jsp-file>myJSPfile.jsp</jsp-file>
</servlet>
<servlet-mapping>
  <servlet-name>myFoo</servlet-name>
  <url-pattern>/main</url-pattern>
</servlet-mapping>

See http://docs.oracle.com/cd/E11035_01/wls100/webapp/configurejsp.html#wp162442 for some more documentation.

flob
  • 3,312
  • 2
  • 32
  • 51
1

You cannot directly read the files inside WEB-INF, it is not public web space, what you can do is you can create a servlet which will forward your request to jsp inside WEB-INF/

jmj
  • 225,392
  • 41
  • 383
  • 426