I have a 3rd party .jsp that I am trying to use in my SpringMVC 3.2 application.
the URL call looks like this:
http://localhost:8080/dms/pcc.jsp/Page/q/0/AttributescumentID=eJQAyAEYASgBJAFMAMgAlADIARgBsAG8AZwBvAC4AdABpAGYA0
I am getting a 404 error. How do I map this in my web.xml?
when I call
http://localhost:8080/dms/pcc.jsp
it works (well, no 404 errors) but I need to send it the parameters.
Changing the 3rd party jsp might be problematic, so how does one map this call straight to the jsp?
Thanks in advance.
Really a broad question. I would start with checking mapping in #Controller, then move into application-config.xml and then web.xml.
It would be nice if you would look at sample Spring Application.
If call to http://localhost:8080/dms/pcc.jsp works, you should try following thing.
http://localhost:8080/dms/pcc.jsp?AttributescumentID=eJQAyAEYASgBJAFMAMgAlADIARgBsAG8AZwBvAC4AdABpAGYA0&otherParams=something
The Page/q/0/ part in URL seems to be messing things up for you. If these also are parameters to be sent, send it the way explained above.
Related
I'm migrating a Play! 1.2 web application and moving to Spring Boot + Spring MVC. Some views contain URLs to other endpoints. For example, I display the book title on the page and next to it I want to add the URL to go the book's details page (e.g. localhost/books/{id}).
In Play! 1.2 the controllers are static, and there is also a Router which can create the full URL for a method belonging to another controller (Router.getFullUrl("BookController.bookDetails", args)), but how do I achieve this with Spring MVC?
Best regards,
Cristian.
If you are trying to get the app/deployed name automatically in .jsp files to make the urls, then please make use of context path. An example below :
<c:set var="context" value="${pageContext.request.contextPath}" />
<script src="${context}/themes/js/jquery.js"></script>
From your requirement "admin.myapp.com","admin-test.myapp.com" are server names right? Something like http://admin.myapp.com/book/{bookId},http://admin-test.myapp.com/book/{bookId}. In Spring app, relative path in jsp can be accessed using pageContext.request.contextPath
I also found the UriComponentsBuilder and ServletUriComponentsBuilder. They are similar to the Play! Framework router and provide methods for building URI's, handling parameters and the query etc. We chose to annotate the controllers' methods using constants and then use the same constants with the UriComponentsBuilder to build back the path and create the request query for GET requests.
I work on a web application that is vulnerable to CSRF(Cross Site Request Forgery) attack. Tomcat 7 has a CSRF prevention filter. I went through the description to configure this filter.
This filter expects that we call HttpServletResponse#encodeRedirectURL(String) or HttpServletResponse#encodeURL(String).
However, I see that in my application we are not using the above mentioned methods. We forward the response using mapping.findForward(target); without touching the request or response object. Can you please let me know how or where can I integrate encodeURL() or encodeRedirectURL() methods in my code?
Any help in this regard is appreciated.
Thanks,
You can Write a Servlet and map all urls (/*) to this servlet in your web.xml file. now you can use encodeUrl method through HttpServletResponse.
It is very interesting for me but I have simple Spring MVC application and JSP page. At Jsp pages which are included I would like to add a cookie to my application. However despite of setting it, It could not resolved at runtime.
this is the code at my included jsp page.
<% response.addCookie(new Cookie("test3","test3")); %>
I prefer writing some of the parts of the our application at jsp level over writing at controller.
What I can just say is that I am using Tuckey UrlRewrite and at instead of my jsp pages when I call my method, it is working fine. And at my called method I can see that the inital response object at my MVC controller is wrapped by another HttpServletResponse object. It seems that headers and cookies could not be changed after forwarded to jsp?
Any help?
PS: I have updated my question to make it clear regarding it is jsp included page.
JSP is part of the response. You need to ensure that that line is exeucted before the response is been committed. Otherwise you end up with IllegalStateException: response already committed in the server logs. So put it in the very top of the JSP page, before any HTML is been sent to the response. Or, better, just put it in a Spring controller or a servlet or filter, far before the forward to JSP takes place.
You also need to ensure that you aren't altering the response inside a JSP file which is included by <jsp:include>. It will be plain ignored. See also the RequestDispatcher#include() javadoc:
The ServletResponse object has its path elements and parameters remain unchanged from the caller's. The included servlet cannot change the response status code or set headers; any attempt to make a change is ignored.
I want to display a custom 404 page not found error page (among others). I'm using Spring 3.0 and don't know how to do this.. I know I can specify a jsp page in web.xml to handle 404 errors. But I want Spring's environment for my error pages. So I tried simply returning a ModelAndView that's basically an error page. But the problem there is once I do this:
response.sendError(HttpServletResponse.SC_NOT_FOUND);
Then the whole request just gets forwarded back to the container's default 404 page. How are we supposed to handle error pages in Spring 3.0?
In Servlet 2.4, response.sendError() and response.setStatus() are treated differently. The former is handled by container, but the latter gives option to provide the response yourself. That means, you have to use response.setStatus(HttpServletResponse.SC_NOT_FOUND). Please also see How do I return a 403 Forbidden in Spring MVC?
I'm working with Spring MVC. I have a controller which returns a new ModelAndView(new RedirectView(getSuccessView())). SuccessView is set as home.htm which is a virtual page that maps to WEB-INF/jsp/home.jsp.
However I'm getting this error:
No mapping found for HTTP request with URI [/Bikes_Spring/WEB-INF/jsp/home.htm] in DispatcherServlet.
As you can see it's searching for home.htm inside the jsp folder... it should be /Bikes_Spring/home.htm
Any ideas how I could resolve this?
Thanks :)
Krt_Malta
In my resolver mapping, I added redirect: in front of home.htm and it did the trick:
<property name="successView"><value>redirect:home.htm</value></property>
What I wanted to do was go from one controller to another... sry I'm still quite a newbie in spring...