Announcement Announcement Module
Collapse
No announcement yet.
<jsp:include /> works after GET but not after POST Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • <jsp:include /> works after GET but not after POST

    Hi,

    I'm using Spring MVC, JSP for a webapp

    I have a Controller with this method:

    Code:
    ...
    
    @RequestMapping( value = "/dashboard/test" )
    public String test( ModelMap model ) {
    	return "dashboard/dashboard";
    }
    
    ...
    The return "dashboard/dashboard" goes to a JSP:

    Code:
    ...
    
    <div id="header">
    <%@ include file="../includes/logo.jsp" %>
    
    <jsp:include page="/top-menu" flush="true" />
    
    <%@ include file="../includes/user.jsp" %>	
    </div>
    
    ...
    Everything works like a charm except the <jsp:include>

    If I make a GET request to /dashboard/test the <jsp:include> works nice and makes a call to the URL /top-menu. If I make a POST request to the same /dashboard/test then everything is ok but <jsp:include> does not execute.

    Does anyone know what I'm doing wrong ?

    Thank you for your time.
    Last edited by oxcar; Apr 5th, 2011, 12:05 PM.

  • #2
    Hello

    Time ago I dont use <jsp:include, I suggest you two things

    1) Use Tiles (series 2 )
    2) Perhaps the flush attribute are making some difference?

    If I make a POST request to the same /dashboard/test
    How are you doing the call with POST?

    If your method in your controller should only handle GET methods
    Code:
    @RequestMapping( value = "/dashboard/test" )
    public String test( ModelMap model ) {
    	return "dashboard/dashboard";
    }

    Comment


    • #3
      Hi,

      In Spring MVC if you dont specify POST, GET, etc ... it accepts request for any of them.

      Code:
      @RequestMapping( value = "", method = RequestMethod.GET )
      accepts only GET

      Code:
      @RequestMapping( value = "", method = RequestMethod.POST )
      accepts only POST

      Code:
      @RequestMapping( value = "" )
      accepts any

      If I make a GET or POST the method is executed ... and goes to the JSP ... but ... jsp:include does not work if I call the controller with a POST request

      And I'm not using Tiles because is a little bit overkill for my needs. But if I dont find a solution for my problem, maybe I'll try that path ...

      Comment


      • #4
        Hello

        In Spring MVC if you dont specify POST, GET, etc ... it accepts request for any of them.
        I can't confirm explicitly this through the documentation

        but ... jsp:include does not work if I call the controller with a POST request
        Show me how you are making the explicit call for each approach (get/post)

        I have two questions, when with the Post approach does not work, it show empty or white such section?, even if yes, check the log files of your container, sometimes happen this, the page is white but the real error are show in the console or in the log file of the container

        Have you tried with
        Code:
        <jsp:include page="/top-menu" flush="false" />
        ???

        Let me know your advance

        Comment


        • #5
          Originally posted by dr_pompeii View Post
          I can't confirm explicitly this through the documentation
          I tell you it's this way ...

          Originally posted by dr_pompeii View Post
          I have two questions, when with the Post approach does not work, it show empty or white such section?, even if yes, check the log files of your container, sometimes happen this, the page is white but the real error are show in the console or in the log file of the container
          I don't see any error on my container's log ... and yes ... there is a blank space where the jsp:include tag is placed ...

          Originally posted by dr_pompeii View Post
          Have you tried with
          Code:
          <jsp:include page="/top-menu" flush="false" />
          It makes no difference, it only flushes the response of that include ...

          Thank you very much for your time ... I'll continue trying ...

          Comment


          • #6
            I found it !!

            My problem was in the Spring Controller that was executed the jsp:include

            It only accepted GET requests, so I changed the controller to accept POST requests too ... so jsp:include calls the controller and it executes for GET and POST requests ...

            ^_^

            Comment


            • #7
              Hello

              It only accepted GET requests, so I changed the controller to accept POST requests too
              I guess using method = RequestMethod.POST, right?

              If yes, I told you, you must use explicitly the RequestMethod, otherwise is used by default the GET approach

              Anyway it work, FYI, use tiles, is better!

              Best Regards

              Comment


              • #8
                I just used

                Code:
                @RequestMapping( value = "" )
                instead of

                Code:
                @RequestMapping( value = "", method = RequestMethod.GET )
                so now it accepts GET and POST

                Comment

                Working...
                X