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?
Related
I have an iframe inside a jsp which is for processing payment using a third party payment provider.
When I get the response from payment provider, I use another jsp file just for breaking out of iframe (using javascript, as I could not find anything to do this in jsp, and probably there is no such way to do it in jsp AFAIK).
Now, the problem for me is the error scenario. When I receive some error from the payment provider, I want to display that on top of the page where I am redirecting to after breaking from iframe.
We use flash attributes for dispalying the error messages while doing redirect from spring mvc using redirect:.
But I am not sure how to do that when using a browser redirect.
One solution (Post/Redirect/Get pattern) I could think of is to append the error respone in the url which I am using in the redirect from breaking out of iframe.
But this would require changes to our jstl tag files and that will be different from the design of our existing code.
Can anyone point me to some better solution for this?
I ended up using session variable.
So just added a session variable in controller, and before the view was passed on from the last controller, copied the session variable into the redirect flash attributes and then it worked. I know this may not sound good enough, but that's how I had to make it work.
I have to create a little webshop for a school-project, but entered in to a problem during the process by updating/refreshing the Servlets.
Description:
I created an index.html file which includes two servlets via iframes, the left side for Navigation-Servlet and on the right the Controller-Servlet does something to show a welcome page (or shows off the categories etc.) - works all fine.
But now I have to implement a login with an small administration.
By clicking in the navigation on Administration, it leads to another Servlet called Administration-Servlet, in the right iframe (actually not over the Controller-Servlet).
There comes up a login mask, where the user put in his username and password. If the login was correct, it leads then to the administration content (not finished by now).
The upcoming problem is now that I somehow have to update/refresh the Navigation iframe too, when the login was successful because there must be the Logout-Button and some entries have to be hidden.
By which "technique" or pattern I can solve this problem? Maybe a little code example would be helpful. :)
Best greets.
Instead of using Iframes to put together the different parts of your site, use dynamic include in your servlets. This will allow you to build the response page server side and therefore dynamically change what is included in a page. When you log in you send the authentication request to the servlet which will then dynamically construct the new response from multiple JSP files.
<jsp:include page="..." />
Another solution is to use a scripting language like Apache Velocity Template scripts to build your responses dynamically. Allowing you to include or exclude information depending on parameters or session context.
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']}
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.
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? :)