• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Place JSP files in WEB-INF Folder

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
I want to place jsp files and images inside WEB-INF folder but I dont
want to change the path of forward mapping inside the struts-
config.xml and also want to use the images directly inside the jsp
pages without giving the path like /WEB-INF/(jsppagename) .Can anyone say what is the procedure and whether I have to
change in the web.xml?Please reply soon.

Enviroment used:Tomcat,Struts,JSP,Hibernate,Spring

Thanks
Manonita
 
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why do you want to place JSPs and images in WEB-INF. Whats the explicit need to do that. You will never be able to call those JSPs.
 
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Raghu is right....
you are violeting jee rules there....pls explain whats your intance behind this...
 
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Milan Jagatiya:
jee rules


??
 
Milan Jagatiya
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Adeel Ansari:

??



it means j2ee architecture rules...
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by rao raghu:
You will never be able to call those JSPs.



No. You can make use of those JSPs using servlets.

But I am not sure about the Struts Controller. I doubted if that would be able to access your JSP pages if you put your pages inside WEB-INF.
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The WEB-INF folder is a place to put things that you don't want to be accessed directly from the web.

If you want direct access to these files, then WEB-INF is the wrong place to put them.
 
Sheriff
Posts: 67749
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When employing the best-practice Model 2 web application pattern -- in which servlet controllers do the processing and then forward to their view JSPs -- it is advised to place the JSPs under WEB-INF so that they can never be directly accessed.

As Ben pointed out, only place the JSPs outside of WEB-INF if you are employing an old-fashioned Model 1 pattern -- in which the JSPs are addressed directly.
[ February 13, 2007: Message edited by: Bear Bibeault ]
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Bear Bibeault:
When employing the best-practice Model 2 web application pattern -- in which servlet controllers do the processing and then forward to their view JSPs -- it is advised to place the JSPs under WEB-INF so that they can never be directly accessed.

As Ben pointed out, only place the JSPs outside of WEB-INF if you are employing an old-fashioned Model 1 pattern -- in which the JSPs are addressed directly.



Indeed.
 
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Bear Bibeault:
When employing the best-practice Model 2 web application pattern -- in which servlet controllers do the processing and then forward to their view JSPs -- it is advised to place the JSPs under WEB-INF so that they can never be directly accessed.

As Ben pointed out, only place the JSPs outside of WEB-INF if you are employing an old-fashioned Model 1 pattern -- in which the JSPs are addressed directly.

[ February 13, 2007: Message edited by: Bear Bibeault ]



Then how do you display the jsp?
 
Bartender
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by M Burke:


Then how do you display the jsp?



The JSP is a constrained resource when you place it inside WEB-INF and it can be accessed from within the application only. That means you have to go through a servlet and the servlet has to forward the request to the JSP. The resource cannot be accessed directly from the outside world.

also want to use the images directly inside the jsp
pages without giving the path like /WEB-INF/(jsppagename)



Directly ? You cannot "embed" an image in a JSP. Load the image by making a reference to it like img src="blabla.jpg"

[EDIT]

You could alternatively, load a image by referencing a servlet name in img src. The servlet should stream the required file to the JSP
[ February 14, 2007: Message edited by: John Meyers ]
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Bear Bibeault:
When employing the best-practice Model 2 web application pattern -- in which servlet controllers do the processing and then forward to their view JSPs -- it is advised to place the JSPs under WEB-INF so that they can never be directly accessed.

As Ben pointed out, only place the JSPs outside of WEB-INF if you are employing an old-fashioned Model 1 pattern -- in which the JSPs are addressed directly.

[ February 13, 2007: Message edited by: Bear Bibeault ]




I agree. Although even for Model 1 applications, I still recommend that you place your JSPs inside WEB-INF, and then create an intermediary JSP.
You do not want to expose your source code to the public. WEB-INF adds a layer of security, as it does not allow client requests to access anything under it directly.

To resolve your issue, create a JSP outside WEB-INF that includes the page you want to display.

i.e.
Your application name is javaranch/
Your original page was: javaranch/Login.jsp
move that page to: javaranch/WEB-INF/pages/Login.jsp
create a new page: javaranch/Login.jsp

Source Code of Login.jsp: (one line only)


Note: You should use the directive (@include) instead of the action (jsp:include) in case the included file (for some reason) needs to set header values or forward/redirect to another page.

Now this would be a lot of work if you have a ton of JSPs to move inside WEB-INF, but making sure that a client cannot access your source code makes it all worth it. (Anyway, you can create a Java program or even a batch file to do just that)

As for your images, that's when I cannot see the point of putting them inside WEB-INF if you don't want clients to access them directly.

Hope that helps
[ February 17, 2007: Message edited by: Hunny Growl ]
 
Bear Bibeault
Sheriff
Posts: 67749
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I really don't see any benefit of creating a one-line intermediary JSP just so you can put the "real" JSPs under WEB-INF.
 
reply
    Bookmark Topic Watch Topic
  • New Topic