File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Spring and the fly likes Display a new view page with form  after submit of a Jsp page in Spring Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Application Frameworks » Spring
Reply Bookmark "Display a new view page with form  after submit of a Jsp page in Spring" Watch "Display a new view page with form  after submit of a Jsp page in Spring" New topic
Author

Display a new view page with form after submit of a Jsp page in Spring

Soumya Rout
Ranch Hand

Joined: Aug 06, 2009
Posts: 49

In my application i need to display new jsp page with form fields and all that rather than a normal success page.


I tried this code , it displaying the next page with fields but its not accessing the specified controller (On submit on page2 as well) .





But if try this code






its showing following exception :

Neither BindingResult nor plain target object for bean name 'frmPage2' available as request attribute.

I'm stuck here. Please someone guide me.


Thanks
Soumya





Mark Secrist
Ranch Hand

Joined: Jul 01, 2003
Posts: 89
To your last question: It probably means you are trying to access this value 'frmPage2' somewhere else (possibly another controlelr or JSP). You renamed the model object to 'user', which is the name it's stored in the request (or session) as.

To your original issue, you say you can display the values but not access the specified controller? Let me see if I understand. You have something like the following:

page1.jsp ->Submit -> controller.onSubmit -> page2 (view w/frmPage2 as the model obj) -> page2.jsp (via view handler)

So far, so good? What controller can't you access? Is it the target controller from the page2 form?
Soumya Rout
Ranch Hand

Joined: Aug 06, 2009
Posts: 49

Yep you are right. Thats the exact flow. When the page2.jsp opens up it doesn't go to a different controller . Rather it access the same controller from it was called.

Now the problem i need to load some data in Bean object through formBackingObject method. But when the page2 loads up it directly comes without moving to the BackObejct method.. And on submit of the page2 it goes to earlier controller..


Mark Secrist
Ranch Hand

Joined: Jul 01, 2003
Posts: 89
I think you may have two problems. The typical pattern when returning a ModelAndView from a controller method is to resolve that view to a JSP (or some other view). Sometimes you need to do more processing or as you indicate, load a new form backing object. In that case you would put a redirect prefix on the view name. Something like:

Then your invocation path would be:
page1.jsp ->Submit -> controller.onSubmit -> redirect to controller2.formBackingObject() -> page2 (view w/frmPage2 as the model obj) -> page2.jsp (via view handler)

The other problem with page2 submit going to the same controller may have to do with the path you define for your action in the page2 form. It has to be a different path and that path has to be mapped to the new controller.
 
IntelliJ Java IDE
 
subject: Display a new view page with form after submit of a Jsp page in Spring
 
Threads others viewed
display exception on formbackingobject
Opening new Window in Spring
Getting a headage..... Cannot find class [...] for bean with name '...' defined in ServletContext re
Command object is not setting up properly
F5 or page refresh calls onSubmit of spring controller - database again updated
IntelliJ Java IDE