Reputation: 1218
I'm developing an MVC portlet using spring MVC. I want to add URL parameter to the URL of the opened page from the corresponding render mapping method. For example for this controller class:
@Controller(value = "SpringMvcController")
@RequestMapping(value = "VIEW")
public class SpringMvcController {
@RenderMapping
public ModelAndView handleRenderRequest(RenderRequest request,RenderResponse response,Model model) {
ModelAndView modelAndView= new ModelAndView("view");
/*What should I add here*/
return modelAndView;
}
}
I want to add some code in order when the view.jsp page is opened a parameter is added to the url like that ?param=value
Is that possible?
Upvotes: 0
Views: 2405
Reputation: 3657
Just add your parameters to your ModelAndView
Object so you can access them in your .jsp
file:
Controller.java:
@Controller(value = "SpringMvcController")
@RequestMapping(value = "VIEW")
public class SpringMvcController {
@RenderMapping
public ModelAndView handleRenderRequest(RenderRequest request,RenderResponse response,Model model) {
ModelAndView modelAndView= new ModelAndView("view");
modelAndView.addObject("objectName", object);
return modelAndView;
}
}
SomeJspFile.jsp:
...
<p>${objectName}</p>
...
If you create your own object and you create all Getters and Setter you even can access attributes of this object like this:
SomeJspFile.jsp:
...
<p>${objectName.attributeName}</p>
...
Upvotes: 0
Reputation: 1664
You can get this parameter from request, like that:
@RenderMapping
public ModelAndView handleRenderRequest(RenderRequest renderRequest, RenderResponse response, Model model) {
HttpServletRequest request = PortalUtil.getOriginalServletRequest(PortalUtil
.getHttpServletRequest(renderRequest));
String param = ParamUtil.getString(request, "param");
...
}
Upvotes: 1