• 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
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to do both?

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

In the MVC model, when the Controller is handling a POST like below, it returns a View (jsp) with the stuff posted.


Using the MVC model, how can I send an HTTP Response (in bytes) right back to the HTTP Requestor AND have the HTTP Response show up in a View like what it is doing now?

The "return "redirect:/business/"+business.getId();" seems to only allow me to show the data in a View. It is an action taken by the Server side. In addition to showing the View, I need to return the whole HTTP Response in a stream of bytes so the client can also display this Response Message (in a stream of bytes) on whatever mobile phone that s/he is using.

Am I making sense or misunderstanding some important points about the MVC model?

Any help will be greatly appreciated.







 
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
I can recommend looking at Spring 3.0 and their implementation of RESTful WebServices. From what you describe, it seems like this might be the best and easiest approach to have a mobile device get the data instead of a "web page"

Good Luck

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


I can recommend looking at Spring 3.0 and their implementation of RESTful WebServices



Hi Mark,

Did you mean the sample projects that come with the Spring 3.x dist? If possible, can you point me to a specific implementation (what, where/which sample project?) that will help me out, please?

I saw many samples that deal with sending data via the HttpServletRequest and HttpServletResponse pair but I have not (or simply do not recognize) found one that I can understand of doing both.

Many Thanks to your response. Can you direct me to specific sample project(s) that I can model after, please?

Much Obliged
 
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
I wasn't referring to any code.

This has little bit, but all it is is your Controller returns a JsonView object

return new JSonView

Just have the Jackson libarary jar in your classpath

http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/view.html#view-json-mapping

For Spring RESTful Web Services you just need to include the ContentNegotiatingViewResolver as a bean definition

http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/mvc.html#mvc-multiple-representations

Good Luck

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

Thank you again so very much for your response and info, Mark.

Unless I really misunderstood the usage of ContentNegotiatingsViewResolver and JsonView objects (if so, please straighten me out), these mechanisms are still only allowing one Response back (i.e. either this View, that View, writing to stream, or pass void to indicate that the Request has been taken care of ....and such).

I am however, trying to find out how to indicate in (return from) the Controller in order to display the data in a particular View as what I do most of the time AND at the same juncture to have the HTTP Response message sent back to the Requestor with XML data.

Hope I am making sense

Any info and ideas will be greatly appreciated.



 
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
In Http, there is one response per one request. You can't ask for two different responses for a single request.

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

Thanks very much for your response, Mark.

I was thinking whether I could use the MVC model to send back an HTTP response as usual but before returning from the Controller to direct data to a predefined View for display as well. So, this is an extra action to take besides responding to the request using the normal route in the MVC structure one way or the other.

I dug into the MVC code somewhat and found a manual but immensely ugly way to achieve this. Having to do this in the MVC model must not be such a novelty and I wonder how folks handle this requirement if they ever had to

Thanks for your follow up and I look forward to hearing any other ideas that anyone may have.

Many Thanks....Mimi

 
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

Mimi Tam wrote:
Thanks very much for your response, Mark.

I was thinking whether I could use the MVC model to send back an HTTP response as usual but before returning from the Controller to direct data to a predefined View for display as well. So, this is an extra action to take besides responding to the request using the normal route in the MVC structure one way or the other.

I dug into the MVC code somewhat and found a manual but immensely ugly way to achieve this. Having to do this in the MVC model must not be such a novelty and I wonder how folks handle this requirement if they ever had to

Thanks for your follow up and I look forward to hearing any other ideas that anyone may have.

Many Thanks....Mimi



Do you mean like return a PDFView or JstlView object from your Controller method. You can definitely do that too, but not both at the same time.

Mark
 
reply
    Bookmark Topic Watch Topic
  • New Topic