Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Issues with <jsp:include> working?

 
Kishor Joshi
Ranch Hand
Posts: 674
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there
this is my header.jsp file


and this is my footer.jsp


in one of My page addStudent I have used these two as follows


Both Inlcude at the position is working fine

What I was expecting if their is no code in the session then user should be redirect to LoginError but when I type its absolute URL then I can also access this page
I am clearing value in the session like this


But still code is not working.

How to solve this?

Thanks
 
Srikkanth Mohanasundaram
Ranch Hand
Posts: 243
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Kishore,

Why are you using ServletContext (think 1 per web context ) ? You should be using the HttpSession object .HttpSession provides getAttribute,setAttribute and removeAttribute methods. You're only showing us the part which you think is the issue, it would help if you elaborate on what is "Absolute URL" which you access and in which Servlet you have this code etc.,

And if this is a new project that you're working on, I strongly recommend you to use HTML5 semantics with a CSS framework like BootStrap.

Thanks
Srikkanth
 
Kishor Joshi
Ranch Hand
Posts: 674
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what is risk of using getServletContext()?
 
Srikkanth Mohanasundaram
Ranch Hand
Posts: 243
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what is risk of using getServletContext()?


There's one ServletContext which is share by the web app. Whereas a HttpSession object is created for each user session. So where do you think you'll keep your session attributes ?

Search this forum , and you'll find this question answered a lot of times.

-- Srikkanth
 
Kishor Joshi
Ranch Hand
Posts: 674
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
although
@Bear
Suggested in my past posts use filter for session tasks

I don't know how to use it.
I have 50 JSP page in my web application and I need to check each page whethar user is logged in or not

How can I acheive this?
 
Srikkanth Mohanasundaram
Ranch Hand
Posts: 243
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why are you accessing the jsp files directly ? It should go inside the WEB-INF folder, they are meant to be used as view files.

But here are the steps that you might need to create a Filter.

1. Create a CustomFilter class which implements Filter interface. ( Rename the class based on your requirements )
2. Implement the doFilter() method
3. In the doFilter() method, check if the user session has an indicator which tell you if he's an admin or no, if not an admin redirect. HttpResponse has methods for redirecting.
4. Configure the filter in your web.xml. This is two step, you define your filter and you also define the URL-mapping mentioning the requests which this filter needs to handle. If all requests has to pass through this filter, you need to use a *.


-- Srikkanth
 
Kishor Joshi
Ranch Hand
Posts: 674
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Srikkanth

Thanks I will try your approach
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!