aspose file tools*
The moose likes JSP and the fly likes Problem with getting JSTL 1.2 to display on the page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Problem with getting JSTL 1.2 to display on the page" Watch "Problem with getting JSTL 1.2 to display on the page" New topic
Author

Problem with getting JSTL 1.2 to display on the page

Daniel Gellman
Greenhorn

Joined: Sep 09, 2012
Posts: 6
I am having a problem with getting my JSP to display after using some JSTL's. The basic concept is that I have an index.jsp page that I am posting an AJAX call on pageload to a servlet that processes some data and passes back an ArrayList of Map objects to the index.jsp page. The JSP then takes that information is is SUPPOSED to place it into a table inside of a hidden div that appears as a Jquery popup dialog when the user clicks on a button. The issue arises after clicking the dialog, the table that SHOULD be there is not. I look at "view source" and the table that should be there is not. When I look at firebug however, in the net property under XHR response I see the table and all populated data just fine and as expected. I'm not sure where the issue is here and I've been working on this for two days any help is greatly appreciated.

edit:
I forgot to mention, I've already checked for nullpointers to make sure that data is passed and it is being passed as expected.

JSP Code:


Jquery AJAX code:


Servlet Code:


Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60082
    
  65

Not sure what this has to do with the JSTL, but in looking at your jQuery Ajax call, where is the success handler that will do something with the response?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Daniel Gellman
Greenhorn

Joined: Sep 09, 2012
Posts: 6


I removed it for a while due to the fact that it wasn't changing the outcome. I was under the impression that once I used the requestDispatcher's forward method the page would reload and I would be able to access the arraylist either way. Maybe it is something with my JQuery that is having an issue?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60082
    
  65

Why aren't you simply using jQuery's .load() method?. It's a bit easier to handle.

I'm also still a bit confused about the moving parts. Let's see if this is right:
  • You have a "parent" page.
  • In that page you perform an Ajax call to a servlet and JSP.
  • The returned response -- an HTML fragment -- gets inserted into the parent page.


  • Good so far?

    If so, which JSP are you having the issue with? The one that generates the parent page? Or the one that generates the HTML fragment via Ajax?
    Daniel Gellman
    Greenhorn

    Joined: Sep 09, 2012
    Posts: 6
    The parent page is index.jsp, the Ajax call is made from index.jsp to a Servlet.

    The servlet reads the single property sent, processes a bunch of data and then I'm using a rd.forward() call to post back to the index.jsp page with the processed data.

    The data being processed is nothing more then a List of Map objects. I am then attempting to use jstl to process that list and create a table inside of a div tag.

    The issue that I am having is that the table is not being created on index.jsp after return from the servlet. I can see all of the table information when looking at XHR responses inside FireBug. However looking at the page, has the opposite effect. Like nothing was done.

    I tried the .load() method but that actually had the same result.
    Bear Bibeault
    Author and ninkuma
    Marshal

    Joined: Jan 10, 2002
    Posts: 60082
        
      65

    Daniel Gellman wrote:The servlet reads the single property sent, processes a bunch of data and then I'm using a rd.forward() call to post back to the index.jsp page with the processed data.

    Why would the Ajax request post back to the parent JSP?

    If you are creating new content to post into the parent page, you should be forwarding to a JSP that will create just that content. Posting back to the parent page in an Ajax request makes no sense at all.

    Whatever is returned from the response will be injected into the parent page. So you certainly don't want to recursively inject the parent page into a location within the parent page!

    Ajax responses never return whole HTML pages -- they either return data (JSON or XML), or HTML fragments. If you want to refresh the entire page, you shouldn't be using Ajax at all.

    I tried the .load() method but that actually had the same result.
    .load() does the same thing as your $.ajax code, but in a more succinct syntax.
    Daniel Gellman
    Greenhorn

    Joined: Sep 09, 2012
    Posts: 6
    Ajax responses never return whole HTML pages -- they either return data (JSON or XML), or HTML fragments. If you want to refresh the entire page, you shouldn't be using Ajax at all


    If not using Ajax then what? As for returning data, if I were to change the ArrayList into a JSONArray object and pass that back using the code in my original post and create the table in the Success portion of my ajax function would that work?
    Bear Bibeault
    Author and ninkuma
    Marshal

    Joined: Jan 10, 2002
    Posts: 60082
        
      65

    Daniel Gellman wrote:
    Ajax responses never return whole HTML pages -- they either return data (JSON or XML), or HTML fragments. If you want to refresh the entire page, you shouldn't be using Ajax at all


    If not using Ajax then what?

    That depends on what it is you actually want to do:
    Replacing the whole page? Use a normal form or link submission.
    Replacing/adding a portion of the page? use Ajax!

    As for returning data, if I were to change the ArrayList into a JSONArray object and pass that back using the code in my original post and create the table in the Success portion of my ajax function would that work?

    Why go through all that?

    If you want to add/replace a table on the page, write a servlet/JSP combination that just returns the table. I do this all the time and it's easy as pie.
    Daniel Gellman
    Greenhorn

    Joined: Sep 09, 2012
    Posts: 6
    Basically I want to add a table into a div on the page... Do you have any starting points for this? Since I was apparently going about it the wrong way lol.

    edt: the page being the index.jsp page that is loaded originally. I dont want to have to truly redirect to a new page.
    Bear Bibeault
    Author and ninkuma
    Marshal

    Joined: Jan 10, 2002
    Posts: 60082
        
      65

    Daniel Gellman wrote:Basically I want to add a table into a div on the page

    OK then. That's a pretty straightforward use of Ajax.

    Use the .load() method targeted to the div to receive the table. The URL should be to the page controller servlet for a JSP that just creates the table HTML.

    Do you have any starting points for this?

    Not really, but it's really quite easy as outlined above.

    Since I was apparently going about it the wrong way lol.

    No problem. Everybody makes mistakes until they learn the best ways to approach things.

    edt: the page being the index.jsp page that is loaded originally. I dont want to have to truly redirect to a new page.

    Right, Once it's loaded there's no need. Your Ajax request only needs to return the new content. They're two entirely separate requests.

    If you want some example client-side Ajax code to look at, you can download the examples for chapter 8 of my book here. It doesn't return a table, but does show how to return different types of HTML fragments.
    Daniel Gellman
    Greenhorn

    Joined: Sep 09, 2012
    Posts: 6
    Thanks a lot! I'll take a look at it.
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Problem with getting JSTL 1.2 to display on the page
     
    Similar Threads
    problem with submit: NullValueInNestedPathException:
    JSP column name hyperlink help
    Implementation of google charts in JSP
    Display of hashmap values using jstl
    Help accessing data in a List of Maps