Refresh a Servlet by another Servlet - java

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.

Related

Spring MVC - add attribute when redirect using browser - breaking from iframe for redirect

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.

Where to store form error message content

I am working on a jsp/servlet web application. I currently use a switch statement within my servlet to select the appropriate error message for each form field (according to the input) and then set that message as a request attribute.
I now want to internationalize the web page (have it available in another language). I was thinking to do this by having a separate directory for the other language and placing the jsps in the other language in that directory. Then a filter will redirect to the appropriate directory via a session attribute.
The problem is that my custom error messages are currently written in the servlet. I was not planning to reroute to different servlets according to the language (ie: same servlet will run for all languages).
The only way that I can think of to do this would be to write each of the custom error messages on the jsp and then have the servlet set a request attribute that identifies the error type.
This solution would require adding a lot of text to the jsps (some fields have 10 different error messages and different messages depending on user type).
Any suggestions of a better approach for making the form error messages multi lingual are welcome.
Also, if there are any general suggestions on a better way to internationalize my site altogether that is also welcome.
Thank you,
.

Liferay application error when trying to access another page

I am making a Java application for Liferay. A simple bookstore. Uploading and displaying the app in Liferay works, but when i try to access other pages then the index page itself I get an error.
This is how my application looks like at the moment. If i for instance click on "All books" in the navigation to the left. I get an error.
This is the error I get, as explained earlier. It says "The requested resource was not found."
""
Any help on what to do, would be greatly appreciated :)
Your first screenshot shows /web/student-life, while the second one shows a URL that looks like a servlet URL, not a portlet URL: /book?action=allBooks.
Note that - in the portal world - you'll lose control over the URLs and you'll need the portal to generate them to you. This typically means that they'll be a lot more ugly than the one you're seeing. You can gain back control (through "friendly URLs" in Liferay) but I'd consider this a second (or third) thought if you're just beginning developing portlets.
Create your action URL with <portlet:actionURL .../> and - for the time being - stay on the same page. Once everything works you can extend this to multiple pages.

How to provide Field Level security in an application using ExtJS for front and Spring for backend?

I have an application which uses Spring for backend and ExtJs for UI.
In this application, users can have variours roles and access rights.
When a user logs in and opens a form, then depending upon her role, its decided that which fields will be displayed to her.
For handling this, we have done following two things:
1. Enclosed the JS code (code which needs to be filtered on basis of role) in spring security tags following way:
< tag start >
js code
< / tag end >
2. Saved all js files as jsp, for example, instead of having a file as test.js - we changed it to test.js.jsp. This forces the backend to parse the security tags before delivering the code to client side.
Though this works fine, but there are following issues which we are ambigous about:
a. Is this the best way of implementing such thing? What other way could this be acheived?
b. After converting js to jsp, the compression tools for JS are not able to minify it due to presence of spring security tags. Could something be done about it?
Looking forward to guidance at above.
Thanks in advance.

Importing secured content using the jstl import tag and have the OSIV filter working correctly

Anyone ever tried the following? (and was successful)
In a web application (A), I am using the <c:import> tag to get secured content from another web application (B) running on the same application server (WebSphere 7). Both apps use Hibernate and Spring's OSIV filter.
Looking at the import tag source, I see that the strategy is that if the url is relative then it includes the content using RequestDispatcher.include() .If the url is absolute, the code opens a URLConnection.
Since I need to keep track of the remote user, I can't do the following:
<c:import url="http://host:port/B/getContent">
Doing
<c:import url="/getContent" context="/B">
instead would work. But with this approach I am not hitting Spring's OSIV filter configured in B. The original (importing) request in A does go through the OSIV filter but it has no effect in B. Hence I am getting the usual "No session or session closed" error for lazy initializations of entities.
I am bit in a catch 22 here and I am wondering if what I am trying to do is actually feasable according to my requirements.
The bottom line is that I did manage to get what I wanted by aggregating my content directly from the client using Dojo, (I am using SSO so the identity of the user gets carried) but I would prefer the other way if it was possible.

Categories