• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

manage get and post?

 
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi

in spring 3, i use annotation, i need to create 3 web page

so i create a controller

first page display only information from a db
second page, user need to enter some data to do a search and result is displayed...

similar thing for the last page, but don't use the same object...

my first problem is how to manage the get and post of second and last page?

does i need a controller for every page?

thanks
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No because you are using Annotations, you can have all three pages call three different methods in your controller

@RequestMapping() has an attribute called requestMethod or method you can set one to RequestMethod.POST and the other to RequestMethod.GET but both have the same URL value.

Mark
 
mark smith
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mark Spritzler wrote:No because you are using Annotations, you can have all three pages call three different methods in your controller

@RequestMapping() has an attribute called requestMethod or method you can set one to RequestMethod.POST and the other to RequestMethod.GET but both have the same URL value.

Mark



same url with same jsp?

so the get will net to have the information of the post...
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

mark smith wrote:

Mark Spritzler wrote:No because you are using Annotations, you can have all three pages call three different methods in your controller

@RequestMapping() has an attribute called requestMethod or method you can set one to RequestMethod.POST and the other to RequestMethod.GET but both have the same URL value.

Mark



same url with same jsp?

so the get will net to have the information of the post...



Yes, I would assume the same jsp page. I also would assume your get is to load the page and the post is after the user clicks submit.

So I type

www.mysite.com/mywebapp/customer.jsp?id=5 in my browser. That will do a get call the one method in my controller that is mapped to GET, It say passes in the RequestParameter of five. In my method code I lookup customer #5 and fill in a Customer object and set it in the Model. The jsp renders and goes to the client browser with the form showing with that customer information. The user changes some data then clicks the Submit button, which submits to the same URL but this time it is a POST. The method in the controller then receives the Customer and sends down to the CustomerService and CustomerRepository to save the updated Customer.

Or with the same URL with no parameter, the same Controller method that is mapped to the GET just creates a new Customer and adds it to the Model. The same jsp page gets rendered with an empty form but a Customer object backing it. The user enters the new data, clicks the Submit button, which submits to the same URL but this time it is a POST. The method in the controller then receives the Customer and sends down to the CustomerService and CustomerRepository to insert the new Customer.

Mark
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic