0

I am having some trouble moving objects rendered to a jsp from a controller to another jsp. The data to be displayed is part of the data in the first jsp. The flow goes like this :

Welcome.jsp (contains a hyperlink)--->invokes a controller(http get) which takes student data(name, mobile no,subject) in a jsp (admissionForm.jsp) --->on submitting form(http post)-->displays the data on admissionSuccess.jsp. this jsp contains a hyperlink(http get) which should display only the student name and mobile number(requestForm.jsp). This page contains other features like submitting a service request (to be implemented).

I am using Spring 3.x with ModelAndView controller. The closest answer I got was to use @SessionAttribute but that came with Model object. Can anyone assist on this ?

My code is as follows :

@RequestMapping(value="/submitAdmissionForm.html", method=RequestMethod.POST)   
public ModelAndView submitAdmissionForm(@Valid @ModelAttribute("student1") Student student1, BindingResult result,HttpServletRequest request,
        SessionStatus status)
if(result.hasErrors())
    {
        ModelAndView model1 =new ModelAndView("AdmissionForm");
        return model1;
    }
    ModelAndView model1 =new ModelAndView("AdmissionSuccess");
    model1.addObject("student1", student1);
return model1;


@RequestMapping(value="/getRequestForm.html", method=RequestMethod.GET) 
public ModelAndView getRequestForm( @ModelAttribute("student1") Student student1,BindingResult result)
{

    ModelAndView model1 =new ModelAndView("RequestForm");
    model1.addObject("student1", student1);
    return model1;
}
tanmoy
  • 1
  • 1
  • you should use a Bean class with properties and getters/setters and on your first form (that submits the student details) you'd use the setter methods and then use the getters to display the details on the 2nd form. that's how I interpret what you desire anyway? – smoggers Jun 23 '15 at 13:23
  • the bean class(Student) have their respective setters and getters. I have used textbox within jsps to map to bean class and submit to post the form.
    @ModelAttribute("student1") Student student1 binds to form You are correct that I display the details in 2nd form. I also need partial bean data in a third form via hyperlink or submit provided in 2nd form.
    – tanmoy Jun 23 '15 at 13:55
  • that's the correct practice then but I'm not sure what your issue is – smoggers Jun 23 '15 at 13:56
  • used session.setAttribute and session.getAttribute as a workaround, it worked.Please share the implementation of @sessionattribute using Spring or any other method in Spring – tanmoy Jun 24 '15 at 09:15
  • use of sessionattribute explained here http://stackoverflow.com/questions/18791645/how-to-use-session-attributes-in-spring-mvc – smoggers Jun 24 '15 at 12:18

0 Answers0