Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Allow Only include

 
Vikas Aggarwal
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a servlet (content.java) which acts as main page. I have a JSP file (footer.jsp) which acts as footer in that page. I am including the JSP in the server using RequestDispatcher include. It works perfectly fine. if I click the url http://localhost/servlet/content

But I don't want users to be able to do this:

http://localhost/jsp/footer.jsp

So actually I want the configuration which allows jsp to be inlcuded Only and not requested or forwarded.

Thanks.

Vikas
[ January 19, 2007: Message edited by: Bear Bibeault ]
 
Mukesh Mittal
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can store jsp in web-inf folder.
 
Stewart Johnson
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use cutom tag for footer
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64822
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Stewart Johnson:
Use cutom tag for footer


Which, especially if you are using JSP 2.0 which supports tag files, is incredibly easy to do and much preferable to includes.
 
Vikas Aggarwal
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot for your answers. I guess I can not go for custom tags because I am including JSP inside a SERVLET. Is there any other option than storing jsp inside web-inf dir?

Thanks.

Vikas
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64822
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Vikas Aggarwal:
I guess I can not go for custom tags because I am including JSP inside a SERVLET.


Huh?

I have no idea what you mean by that.
 
Vikas Aggarwal
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I meant that I can not use the tags inside a servlet. So using custom tag is not an option. I will have to use dispatcher. Is there any other way to do this and protect the footer.jsp?

Thanks,
Vikas
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64822
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So you are generating the main page with a servlet and including JSPs for the footer? That's an odd thing to do. Why not use a JSP for the main page as well?

But back to the original issue, placing the footer.jsp under the WEB-INF hierarchy will prevent direct addressing.
 
Vikas Aggarwal
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks. Actually my company has acquired an application which has servlets as main content pages and we are given task to customise it. So we are using JSPs as footer and header. The main content pages can not be changed to JSPs now.

Thanks. I will keep my JSPs inside web-inf.

Vikas
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic