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']}
Related
I'm learning about servlets and JSP and I try to make an app. The app is from this page
This is the structure of the app:
And I put all the JSP in WEB-INF:
When I try to run any jsp it's not working, I get this error: HTTP Status 404 – Not Found... Description The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.
If I move the jsp in WebContent the app is working succesfully. But I want to keep the jsp in WEB-INF. What should I do? Thanks in advance!
Seems i got your problem. If you have servlet class write code to forward to jsp page like this. Because you have put your jsp page inside WEB-INF/view
request.getRequestDispatcher("/WEB-INF/view/homeView.jsp").forward(request, response);
I am using Liferay DXP SP7. I'm trying to get Liferay's SessionErrors and SessionMessages to add success & error messages to a page containing a custom portlet via an overridden Liferay MVCAction class
- com.liferay.dynamic.data.lists.form.web.internal.portlet.action.AddRecordMVCActionCommand. I'm using the technique explained here to override this internal class because we need to augment some of the Liferay forms functionality by adding things like the ability to edit a form after it's been submitted. This is working just fine. The issue I am running into is that I can't seem to get Liferay's SessionMessages and SessionErrors functionality to work. All I want to do is display error or success messages to the user to let them know if a form save worked. My forms are displayed by a custom portlet that retrieves forms via ajax call to Liferay's DDLFormPortlet (which actually calls my custom AddRecordMVCActionCommand). In the custom AddRecordMVCActionCommand I add success or error messages using SessionMessages.add(actionRequest, "formSaveSuccess"); or SessionErrors.add(actionRequest, "formSaveError");. I have my Language.properties file in src/main/resources/content with the follownig content:
form-save-success=Report saved successfully.
form-save-error=An unexpected error occurred while trying to save the report, please try again.
My JSP page has the following required imports & tags:
<%# taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui" %>
<%# include file="/init.jsp" %>
<liferay-ui:success key="formSaveSuccess" message="form-save-success" />
<liferay-ui:error key="formSaveError" message="form-save-error" />
I have followed the instructions found in Liferay's documentation here to add my languages keys, set up the JSP & add the messages to the session in my MVCAction class. I have read and re-read these instructions several times and everything appears to be set up correctly. I get no error messages in the log, yet my success & error messages never show up. Any help that someone could provide would be very helpful.
I'm developing web application using Spring MVC and Thymeleaf. What is the correct way to make links of pages work regardless of where the application deployed? For example, if I write
Link
and deploy my application not to /, but in /app/, link will not work.
I thought about getting current path in every Controller method like this: request.getContextPath() and than using it in every link on the page, but maybe there is a way to do it better?
If you are using Thymeleaf, you should be able to use <a th:href="#{/about}">Link</a> assuming that <html xmlns:th="http://www.thymeleaf.org"> has been declared. I think this does require using SpringTemplateEngine.
I have a problem in Struts 2.
Using jQuery and CSS template in my web project .
Problem: When using dispatcher in struts.xml, layout of my project get disturb means jQuery didn't work fine,but at same time when using redirect in xml file..its work fine for me, but by using redirect I did not get default behaviour of struts means I have to pass parameter from action to jsp with url.
like this
<result type="redirect">index.jsp?username=$username</result>
I want the default behaviour and my layout remain same.
create a new jsp file say call it css_js.jsp, then include this file in your pages, so that when you move from pages to pages your layout remains same.
In case you are using tiles then in the mainLayout.jsp you can include all your required js and css files
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? :)