Uploaded image for project: 'Click'
  1. Click
  2. CLK-334

Form action incorrect when using JSP

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 1.4, 1.4-RC3
    • Fix Version/s: 1.5 M1, 1.4.1
    • Component/s: core
    • Labels:
      None
    • Environment:
      java 1.6, Resin 3.0.23

      Description

      I'm using JSP for pages with a template JSP used for all pages. The click framework will forward to the template JSP which will in turn include the page's JSP. If I put a Form on my page, the form's action value comes from the getActionURL which determines the value to use based on the value of getRequestURI(). However, because the original template JSP has been forwarded to, the value at this point is of the template, not the page. At least this is the case in the Resin environment in which I'm working. To get my pages to work, I modified the Form's getActionURL as show below, based on the information here: http://www.caucho.com/resin-3.0/webapp/faq.xtp#forward

      Here's my mod to Form that solves my problem:

      /**

      • Return the form "action" attribute URL value. The action URL will be
      • encode by the response to ensure it includes the Session ID if required.
        *
      • @return the form "action" attribute URL value.
        */
        public String getActionURL()
        Unknown macro: { HttpServletRequest request = getContext().getRequest(); HttpServletResponse response = getContext().getResponse(); String requestURI = (String)request.getAttribute("javax.servlet.forward.request_uri"); if ((requestURI == null) || (requestURI.length()==0)) { requestURI = request.getRequestURI(); } return response.encodeURL(requestURI); }

        Activity

        Hide
        sabob Bob Schellink added a comment -

        Hi Chas,

        Thanks for your report, really appreciate it.

        Does your JSP border page use <include page='$

        {forward}

        '/>

        Also the check above:

        requestURI.length() == 0

        is that needed for Resin or its just a precaution?

        regards

        bob

        Show
        sabob Bob Schellink added a comment - Hi Chas, Thanks for your report, really appreciate it. Does your JSP border page use <include page='$ {forward} '/> Also the check above: requestURI.length() == 0 is that needed for Resin or its just a precaution? regards bob
        Hide
        sabob Bob Schellink added a comment -

        Here is a method we can add to ClickUtils and call from Form and Link* controls:

        public static String getRequestURI(HttpServletRequest request) {
        // See section 8.3 of the Servlet 2.3 specification.

        String requestURI = (String)
        request.getAttribute("javax.servlet.include.request_uri");
        if (requestURI != null)

        { requestURI = StringUtils.replace(requestURI, ".jsp", ".htm"); }

        else

        { requestURI = request.getRequestURI(); }

        return requestURI;
        }

        Show
        sabob Bob Schellink added a comment - Here is a method we can add to ClickUtils and call from Form and Link* controls: public static String getRequestURI(HttpServletRequest request) { // See section 8.3 of the Servlet 2.3 specification. String requestURI = (String) request.getAttribute("javax.servlet.include.request_uri"); if (requestURI != null) { requestURI = StringUtils.replace(requestURI, ".jsp", ".htm"); } else { requestURI = request.getRequestURI(); } return requestURI; }
        Hide
        chas Chas Erickson added a comment -

        Hi Bob, now that you mention it, I believe you are absolutely correct that the replacment of .jsp with .htm will be needed. That's great.

        Regarding your other comment, the check against length 0 was just a precaution, it's probably not needed.

        -Chas

        Show
        chas Chas Erickson added a comment - Hi Bob, now that you mention it, I believe you are absolutely correct that the replacment of .jsp with .htm will be needed. That's great. Regarding your other comment, the check against length 0 was just a precaution, it's probably not needed. -Chas
        Hide
        sabob Bob Schellink added a comment -

        Fix checked into trunk and backported to 1.4.1

        I am resolving this issue for now. If there are still issues feel free to reopen it again.

        Show
        sabob Bob Schellink added a comment - Fix checked into trunk and backported to 1.4.1 I am resolving this issue for now. If there are still issues feel free to reopen it again.

          People

          • Assignee:
            sabob Bob Schellink
            Reporter:
            chas Chas Erickson
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development