-2

In my spring mvc application,I am facing a problem of page reloading on every request.Is there any way to restrict that.To be more specific,When I return the name of index.jsp page from controller it will obviously reload the page.How Can I restrict that thing in the index.jsp page.Suppose some part of the page is required to interact with Database and it should be shown on the same index.jsp page as well.How I can achieve this requirement without reloading the index.jsp page completely.Could you please provide me some example for that.

Stunner
  • 961
  • 2
  • 19
  • 39

2 Answers2

0

You can use Filter for that. I am not providing any code here, just try to explain the concept.

Filters have a wide array of uses; the Servlet 2.3 specification suggests the following uses:

  • authentication filters
  • logging and auditing filters
  • image conversion filters
  • data compression filters
  • encryption filters
  • tokenizing filters
  • filters that trigger resource access events
  • XSL/T filters that transform XML content
  • MIME-type chain filters

servlet filter

Use a Filter when you want to filter and/or modify requests based on specific conditions.
Use a Servlet when you want to control, preprocess and/or postprocess requests.

Filter are best suited for authorization, because it can be configured to run for all pages of a site. So you only need one filter to protect all your pages.

Useful Links:

  1. filter tutorial
  2. filter in detail
  3. referred answer
  4. Oracle tutorial on Filter
Community
  • 1
  • 1
Aniket Kulkarni
  • 12,825
  • 9
  • 67
  • 90
0

sorry if i missunderstanding you!

i don't know what do you want to do but i can imagine the following solution.

first direct call to jsp should check a session value, if not exists, redirect from jsp to servlet, in the servlet do what you wand and finally put this session value, and redirect back to jsp.

a good concept depends on what you want to do exactly. You can manage this issue using a PhaseListener or a Filter. but if you just want to manage this one redirect, then no need of Filter or PhaseListener

Rami.Q
  • 2,486
  • 2
  • 19
  • 30