Announcement Announcement Module
Collapse
No announcement yet.
Major Question: URL and HTML encoding Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Major Question: URL and HTML encoding

    Hi, I'm figuring out how to best use the Spring framework and there's just two things coming up all the time thatdon't seem to be properly addressed by spring or servlet docs.

    1) context-relative URLs
    2) escaping text for output

    Now I can do these in JSTL (not that the doc actually recognized these important tasks, whatsoever) but I'm constructing args for message formatting and wish to accomplish these standard basic tasks programatically; from my Controller or HandlerInterceptor.

    QUESTION:
    What is the correct/ best way to perform standard encoding on URLs and text for Response output, from a controller or similar?

    I've looked at ResponseUtils, 3x TagUtils, HttpServletResponse, HttpServletRequest etc. Now I want a convenient and ready-to-use way to accomplish these basics.


    I'll probably write up the results in some form, so I'm trying to get the best/ most correct answers in this area. Thanks in advance!


    Cheers,
    Thomas
    www.powermapjdo.com

  • #2
    I'm not sure you want your controller classes aware of the underlying view technology. If you choose to make HTML ready messages before commiting into a view, you're tying yourself to HTML views (don't forget XML, PDF, spreadsheets, ... ones).
    For contexte relative URL, it is a bit different as you have already commited to HTTP technologies and you could access the servlet context to generate some context aware url, however, in this case too, I'd prefer to let the view technology handle this. I do love the c:url tag from JSTL and I really miss it in standard in freemarker. I think it does the right job at the right place and there's no need to try to replace it.

    Olivier

    Comment


    • #3
      Olivier,

      You're right, it would be nice if the Controller were able to be agnostic of View technology.

      The Controller however is by definition operating in the domain of URL requests and so our API should have first-class reading and output of Context-Relative URLs.

      Now the problem as I see it, is that I want to dynamically format up a message and the <c:url> and <c:out> tags are the only API which is first-class aligned with this requirement and appropriate to solve the problem; but this stuff is statically compiled into the .jsp View technology.

      Perhaps however, I could possibly push more of the message formatting to the .jsp? Push a MessageFormat (i think) and an array of args to the .jsp, further encode some of the args as 'url' or 'out escapeXml=true' and then execute the MessageFormat there...

      As far as I'm concerned this would be a tentative rather than an immediate best solution. The Controller is, if not 100% in the HTML domain, still returning HTTP responses and 90% aligned with HTML. I'd expect a correctly designed API to make basic encodings available for its primary and common input/ output forms.


      Cheers,
      Thomas

      Comment


      • #4
        I just call ${response.encodeURL("/my/url")}. I do that with ALL my urls in HTML views. This allows servlet filters to process the URL if necessary (i.e. URL outbound rewriter, which is kind of mod_rewrite for outgoing urls). It's also required to keep track of the session id if someone disabled cookies.

        You can get a FreeMarkerView class that supports putting the response object on the model here:

        http://opensource.atlassian.com/proj...browse/SPR-929

        or direct link:
        http://opensource.atlassian.com/proj...arkerView.java

        Hopefully it will make it into the real thing soon.

        -andi

        Comment

        Working...
        X