Results 1 to 7 of 7

Thread: A web-app with a non-HTML front end

  1. #1
    Join Date
    Sep 2009
    Posts
    5

    Default A web-app with a non-HTML front end

    If you were developing a web-app which used something like Flex/Silverlight/JavaApplet for the front-end instead of HTML pages, how would this best fit into using Spring?

    I was thinking you could send requests to the server in 3 easy ways

    1)server exposes standard web-service
    2)server exposes a REST web-service
    3)server simply has little 'views' e.g JSP pages, which send XML/JSON data as the response to a standard HTTP request... similar to how AJAX can be done very easily.

    All discussion welcome.

  2. #2
    Join Date
    Jan 2006
    Location
    Seattle, Washington
    Posts
    467

    Default

    Please avoid doing #3 if you can help it. JSPs should not be doing things like that.

    #2 is probably the best model, unless you really needed real SOAP web services for some reason. You don't technically need to implement REST, however. Spring MVC controllers can return XML or JSON views from normal non-REST requests (even if they are "conceptually" REST requests).

    If you want to implement a real REST handler, Spring 3.0 does that out of the box, but 3.0 isn't quite done yet. You could integrate either Apache CXF or Jersey into 2.5.x, both of which are pretty popular. I haven't personally done Jersey. Integrating CXF to implement a REST handler was pretty easy.

  3. #3
    Join Date
    Sep 2009
    Posts
    5

    Default

    Quote Originally Posted by dkarr View Post
    Please avoid doing #3 if you can help it. JSPs should not be doing things like that.
    Agreed. In a non-Spring web-app I guess using raw servlets is better than JSP for this.

    #2 is probably the best model, unless you really needed real SOAP web services for some reason. You don't technically need to implement REST, however. Spring MVC controllers can return XML or JSON views from normal non-REST requests (even if they are "conceptually" REST requests).
    So you mean similar to #3, but we don't abuse JSPs? Are you saying there are standard XML/JSON Views around, or that we can easily create a custom View to send back an XML response? Or did I miss the point entirely?

    It seems I am right in thinking none of this totally changes the server-side architecture much though from a typical web-app?

  4. #4
    Join Date
    Jan 2006
    Location
    Seattle, Washington
    Posts
    467

    Default

    Quote Originally Posted by JDX View Post
    So you mean similar to #3, but we don't abuse JSPs? Are you saying there are standard XML/JSON Views around, or that we can easily create a custom View to send back an XML response? Or did I miss the point entirely?
    I believe there are semi-standard or standard views for returning XML/JSON responses, but it's pretty trivial to construct one from a XML or JSON serializer.
    It seems I am right in thinking none of this totally changes the server-side architecture much though from a typical web-app?
    Hard to say what "typical" means. If you have a clean design that has a front controller that dispatches to a handler that returns a response stream, then implementing REST by itself simply implies the construction of an intelligent URL parser and dispatcher. With CXF/Jersey/Spring3.0, this can all be done with simple annotations. As REST in Spring 3.0 integrates directly with Spring MVC, the response generation mechanisms (Spring MVC) are separated from the input handling mechanisms, whereas CXF and Jersey do their own XML or JSON response generation, which is slightly easier to configure than with Spring 3.0 (because there are fewer options).

  5. #5
    Join Date
    Sep 2009
    Posts
    5

    Default

    I didn't quite follow all that, I'm still pretty new to Spring in general so anything not in 'making a Spring-based webserver 101' is a little confusing to me! Could someone go into a little more detail?

    Coming back to this:
    You don't technically need to implement REST, however. Spring MVC controllers can return XML or JSON views from normal non-REST requests
    The 'you don't need REST' comment I interpret as meaning:
    a)the client (JS/Flex/Silverlight/anything) can send a bog-standard HTTP request to an URL with a bunch of parameters, e.g http://www.mysite.com/getFavouriteColor?user=123
    b)Spring intercepts this and directs it to a custom controller
    c)the controller uses a custom View which outputs XML/JSON which is finally sent back to the client as the HTTP response.

  6. #6
    Join Date
    Jan 2006
    Location
    Seattle, Washington
    Posts
    467

    Default

    It's time to open up the documentation. Open up the Spring reference doc and read the Spring MVC section.

    In addition, the following is a simple reference for creating a JSON view: http://www.ajaxprojects.com/ajax/tut...emid=515#start . I found this from a simple google search.

  7. #7
    Join Date
    Sep 2009
    Posts
    5

    Default

    That JSON example is very helpful, thanks. Looks like I was kind of on the right track there.

    Otherwise, yes obviously I need to get a better handle on SpringMVC as a whole

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •