Results 1 to 8 of 8

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

  1. #1
    Join Date
    Apr 2008
    Location
    Ciudad de Mexico
    Posts
    13

    Default <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 at 11:05 AM.

  2. #2
    Join Date
    Aug 2006
    Location
    Arequipa-Peru / South America
    Posts
    2,796

    Default

    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";
    }
    - Manuel Jordan

    Kill Your Pride, Share Your Knowledge With All
    The Fear Of The LORD Is The Beginning Of Knowledge, But Fools Despise Wisdom And Discipline. Proverbs 1:7

    Blog


    Technical Reviewer of Apress

    • Pro SpringSource dm Server
    • Spring Enterprise Recipes: A Problem-Solution Approach
    • Spring Recipes: A Problem-Solution Approach, 2nd Edition
    • Pro Spring Integration
    • Pro Spring Batch
    • Pro Spring 3
    • Pro Spring MVC: With Web Flow
    • Pro Spring Security

  3. #3
    Join Date
    Apr 2008
    Location
    Ciudad de Mexico
    Posts
    13

    Default

    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 ...

  4. #4
    Join Date
    Aug 2006
    Location
    Arequipa-Peru / South America
    Posts
    2,796

    Default

    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
    - Manuel Jordan

    Kill Your Pride, Share Your Knowledge With All
    The Fear Of The LORD Is The Beginning Of Knowledge, But Fools Despise Wisdom And Discipline. Proverbs 1:7

    Blog


    Technical Reviewer of Apress

    • Pro SpringSource dm Server
    • Spring Enterprise Recipes: A Problem-Solution Approach
    • Spring Recipes: A Problem-Solution Approach, 2nd Edition
    • Pro Spring Integration
    • Pro Spring Batch
    • Pro Spring 3
    • Pro Spring MVC: With Web Flow
    • Pro Spring Security

  5. #5
    Join Date
    Apr 2008
    Location
    Ciudad de Mexico
    Posts
    13

    Default

    Quote Originally Posted by dr_pompeii View Post
    I can't confirm explicitly this through the documentation
    I tell you it's this way ...

    Quote 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 ...

    Quote 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 ...

  6. #6
    Join Date
    Apr 2008
    Location
    Ciudad de Mexico
    Posts
    13

    Default

    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 ...

    ^_^

  7. #7
    Join Date
    Aug 2006
    Location
    Arequipa-Peru / South America
    Posts
    2,796

    Default

    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
    - Manuel Jordan

    Kill Your Pride, Share Your Knowledge With All
    The Fear Of The LORD Is The Beginning Of Knowledge, But Fools Despise Wisdom And Discipline. Proverbs 1:7

    Blog


    Technical Reviewer of Apress

    • Pro SpringSource dm Server
    • Spring Enterprise Recipes: A Problem-Solution Approach
    • Spring Recipes: A Problem-Solution Approach, 2nd Edition
    • Pro Spring Integration
    • Pro Spring Batch
    • Pro Spring 3
    • Pro Spring MVC: With Web Flow
    • Pro Spring Security

  8. #8
    Join Date
    Apr 2008
    Location
    Ciudad de Mexico
    Posts
    13

    Default

    I just used

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

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

Tags for this Thread

Posting Permissions

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