Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring MVC & JSP: How to pass a parameter from the controller to JSP?

I have 2 JSP pages, in the first I have input text forms, I want to display the values inserted in another JSP page. (using Spring MVC).

like image 327
RaisMEd Avatar asked Jun 04 '13 21:06

RaisMEd


People also ask

What is Spring and Spring MVC?

Spring Boot is considered a module of the Spring framework for packaging the Spring-based application with sensible defaults. Spring MVC is considered to be the model view controller-based web framework under the Spring framework. Use. For building a Spring-powered framework, default configurations are provided by it.

What is difference between MVC and Spring MVC?

The MVC term signifies that it follows the Model View Controller design pattern. So, Spring MVC is an integrated version of the Spring framework and Model View Controller. It has all the basic features of the core Spring framework like Dependency Injection and Inversion of Control.

Is Spring MVC easy?

To answer your questions, Spring is easy to learn because the whole framework is designed to work with POJOs, instead of relying on special interfaces, abstract classes or such.

Is Spring MVC a programming language?

Spring MVC framework is an open source Java platform that provides comprehensive infrastructure support for developing robust Java based Web applications very easily and very rapidly. Spring framework was initially written by Rod Johnson and was first released under the Apache 2.0 license in June 2003.


1 Answers

Put your variable that you want to transfer to the next page in a hidden field (put the fields in the same form which take you to next page. then get your parameter by JSTL. this is an example :

<form:form action="/nextPage" method="POST" commandName="cmd">

         <input type="hidden" value="Myname" name="nom" />
         <input type="hidden" value="myPPR" name="ppr" />

</form:form>

the controller :

@RequestMapping(value="/nextPage",method=RequestMethod.POST)
    public String FicheService(@ModelAttribute CMDBean cmd,BindingResult result,@RequestParam("nom") String nom, @RequestParam("ppr") Integer ppr,ModelMap model){
    model.addAttribute("ppr", ppr);
    model.addAttribute("nom", nom);


}

then get them in the second page like that :

<c:out value="${ppr}" />
<c:out value="${nom}  />
like image 96
Souad Avatar answered Sep 28 '22 08:09

Souad