Liferay application error when trying to access another page - java

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.

Related

ServletException in:/layouts/menu.jsp null' in one portion of jsp page where redirect link is there

There is a java struts 1.1 web application developed using java 4 and which is now being upgraded to openjdk 8. While running the application I am getting this servlet exception in the UI screen in one portion which consists of a link to different jsp page. How to fix this issue?
[ServletException in:/layouts/menu.jsp] null'
I had the same issue. I think it's getting hung up somewhere in your Action class, as soon as you enter the entry point of your Action class. Place some system outs to the console and check how far you can get with it. Then if you don't see your next system out, then that's where the issue may be hanging around.

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.

Spring equivalent of tilde (~) for routing from ASP.NET?

Sorry in advance if this is something trivial
In ASP.NET I remember you could direct your routes to
Login
and you didn't have to worry about anything URL related (if your project is on localhost:1234 or localhost:1234/myproject/ or whatever), ASP.NET would do the job for you.
Is there an equivalent for that in Spring. Currently when I start up my project, using GlassFish, it starts up at url localhost:8080/myproject and the resources (css, js...) aren't even being loaded until I add another / in the end (localhost:8080/myproject/).
All my routes are on the first URL parameter and my GET variables aren't even RESTful, simply because if I go one / more, my routing is going to go wrong, ie.
Home //will go to localhost:8080/home (not the project scope)
Home //is fine until I go to another / in url...
//...(/foo/bar), then it goes all the way up
//to localhost:8080/foo/home
I tried to google this, but every time I try to google something equivalent to ASP.NET, I just get a lot of ASP.NET tutorials (nothing Spring related).
So.. is there any way to keep the url consistent, something in the lines of:
Login
or
Login
How is it normally done in (commercial) applications? What's the best practice in this?
You need to use the Spring Tag library.
First import the tag library in your JSP:
<%#taglib uri="http://www.springframework.org/tags" prefix="spring"%>
Now, instead of writing a raw URL, you use <spring:url>, for example:
Login
Or you can assign the value to a variable and reference it:
<spring:url value="user/login" var="login"/>
Login
Which you prefer is a matter of preference.
The tag will then work out the web application context, etc, and replace <spring:url ... with the full URL.

Refresh a Servlet by another Servlet

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.

Deploying Struts2 Application without ContextPath

I've got a struts2 application running under a contextpath "/path" on my local tomcat without problems. When I deploy it on a webserver (using a proxy to redirect from "http://www.domain.com" to "myserver:8080/path/") Struts does all kinds of strange things.
First, it includes the context in -tags. That can be turned off by an attribute. But sadly, it also includes the path in the action attributes of my forms, so a login form points to "http://www.domain.com/path/login.action" instead of "http://www.domain.com/login.action" ...
Is there a possibility so somehow change the default context that is added here or turn this off for forms? (I'd like to keep the -tags, only way round seems to be to use default HTML forms.) Thanks in advance!
I found that others also had the problem, but the framework makers don't seem to think that this is an issue. My solutions:
use includeContext="false" in all s:url-tags
instead of the s:form tag, use a usual form, set the action to "actionname.action" and include a simple table with tablerows () for each field. You still can use s:textfield and such.
sadly HTTP sessions won't work anymore as they get set for the path "/path" (the ApplicationPath). This is due to the cookie that saves the JSESSIONID being set to /path. This means that your visitors will only get session variables stored when they're at http://www.domain.com/path/login.action and that those will be lost when they get redirected back to http://www.domain.com/interestingstuff.action ... my solution is a hack that requires setting the JSESSIONID cookie clientside via JavaScript as described here: Struts2: Session Problem (after reverse proxy)
Hope this helps someone ... if you find nicer solutions, please let me know. :-)
Though am answering very late to this question, but I reached this page recently when I was facing the same problem.
The application that I was working upon was appending the context-root viz. 'myContextRoot' to my url on localhost and it was working perfectly there. For eg., as mentioned above the action 'myAction' was becoming
http://localhost:8050/myContextRoot/myAction.action
But the moment I deployed it on a server, it stopped working, then after searching like hell, I found a solution for me. I am deploying an EAR file on glassfish and there we have a file application.xml. In application.xml I had a tag 'context-root' whose value was 'myContextRoot' which I changed to '/' and after that I got my url as on localhost and
Hope it may help :)

Categories