aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes Can I use ajax to change the page source of a JSP Include ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Can I use ajax to change the page source of a JSP Include ?" Watch "Can I use ajax to change the page source of a JSP Include ?" New topic
Author

Can I use ajax to change the page source of a JSP Include ?

billy beaker
Greenhorn

Joined: May 07, 2009
Posts: 2
I can't find a clear answer on the web for this one. I would like to load a different JSP include page when a user changes a drop down menu.

I would rather not use a hidden div and just change the display property.

Does anyone know how to implement this?

I am using Spring backend and YUI to make the ajax call.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60997
    
  65

Ajax has nothing to do with JSP includes whatsoever. All of the JSP actions take place on the server in order to format the HTML page to send to the browser. The fact that a JSP (or anything else) created the HTML is completely moot.

Whatever you want to do to the page once it's delivered to the browser has nothing to do with how the page was generated on the server.

With that in mind, care to ask your question again? Because I'm not sure what you are really asking.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
billy beaker
Greenhorn

Joined: May 07, 2009
Posts: 2
What I would like to accomplish is switch the jsp include file when a user changes a drop down menu.

When it changes, a different jsp file loads. Each drop down option has a file associated with it that would switch accordingly.

I hope that helps explain what I want to do.

To quote a forum post I found that sums up my problem exactly:

"I have jsp page which contains a select tag and a div..
<div id="detailsBody">
<jsp:include page="investigation-types/vehicular-accident.jsp">
</jsp:include>
</div>

when the select onchange event happens what I wish to do is change the page property of the <jsp:include> to another jsp page without reloading the whole page..just the div"
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Than make an Ajax call to the server and replace the content of the div.

If you use a library such as jQuery, it is easy as pie.

Eric
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60997
    
  65

bill petrin wrote:What I would like to accomplish is switch the jsp include file when a user changes a drop down menu.

Apparently you didn't understand my post. Once again, there is no concept of a JSP include, or anything to do with JSP, once the response leaves the server, so the whole question of "replacing the include file" is moot. Can't be done. Period.

Now, as Eric pointed out, you can replace the DOM elements that resulted from the include, but you cannot, I repeat cannot, interact with the include itself in any way.

With a library such as jQuery, it's easy to instrument the dropdown to fire off an Ajax call to fetch new content to insert into the DOM, or to replace elements in the DOM.

But if you keep focusing on the JSP include, you will get nowhere.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Can I use ajax to change the page source of a JSP Include ?