Is it possible to have some kind of empty JSP (index.jsp) with ~only auto redirecting to servlet?
Or can I start my web app not from page (jsp/html) but from servlet? (web.xml says no)
I have logic needed in (for example) index.jsp page inside my Logic.java servlet - that's why I need to use servlet before any useful JSP (don't want to mix logic with UI using scriptlets)
Does it can be done?
I think what you want is
<jsp:forward page="/controller-name" />
or you can redirect using
<c:redirect page="..."/>
The difference is first will forward which means the user's url won't change and the latter will change the user's url.
That's possible if you provide an empty index.jsp and map the servlet on
<url-pattern>/index.jsp</url-pattern>
The servlet should in turn however forward to a JSP to present the results. The very same index.jsp maybe? :)
Related
It says in the Oracle webapp documentation
If a resource matches a URL pattern in both a servlet-mapping and a
jsp-property-group, the pattern that is most specific applies
(following the same rules as the servlet specification).
Why can't both be applied? Say I don't want a user to go directly to a jsp file, rather have it go through a servlet first, which will then forward that jsp to the user. But I also want that jsp file to have a prelude, coda, etc. Is there a collision here that one of them has to win over the other?
If you don't want the user to hit your JSP, stuff it underneath WEB-INF. The container can see those JSPs, but nothing from outside can.
Then, you'll see, the Servlet will have one URL, while the JSP will have a separate, different URL.
The external URL, the one representing the Servlet, doesn't (necessarily) conflict with the URL for the JSP. You then code up the property group on the JSP file itself.
Your Servlet will do its processing, and then FORWARD to the JSP (it can not REDIRECT, since the JSP is buried in WEB-INF, and the outside world can not see it).
The property group mapping works against the URL of the resource your are FORWARDing to, the JSP.
So, there's no conflict here. Simply two different URLs, one taking the initial request (the Servlet), the other the rendered resource that you FORWARD too.
I have spring mvc application using apache tiles.Main file is template.jsp which includes header.jsp, then got place for potential messages and footer.jsp included.
Is there a way to check within jsp page ( using JSTL ) on which page I'm inside header.jsp code ?
Normal way of getting page URL are not good because
${pageContext.request.servletPath}
Always get's me the page I supposed to be so , template:
/WEB-INF/tiles/template.jsp
Is there a way to do it somehow , without adding anything to model from within spring?
(Because this is one of way to do this )
You can access the page URL (as it would appear in the browser) using the following EL in your JSP:
${requestScope['javax.servlet.forward.request_uri']}
Is it possible to make JSP page that updates without reloading
I have search this for a little while now and all of them directs to using AJAX or JQuery...
But I need to use JSP is it possible?
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.
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
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:
filter tutorial
filter in detail
referred answer
Oracle tutorial on Filter
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
I have a simple web application running in Tomcat. There is a servlet which is forwarding the request and response to a jsp page which in turn prints something to the browser.
Now I have an aspect which captures the response. In this case a HttpServletResponse. Now what I want to do is that I want to capture the reponse and add some content in it to be displayed in the browser through JSP page.
I dont want to add the content in the jsp page rather I want to add some content without changing my jsp or servlet, using runtime weaving functionality of aspectJ.
I have not been able to figure out any solution yet.Please help me with this.Thanks.
We don't do that with the response. Request object is a better candidate for that. You must understand that JSP is a server-side technology, therefore your request used to be alive in the JSP page.
Moreover, I would suggest you to look at Servlet Filters, those are meant for this kinda scenarios.