• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
billy beaker
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64623
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
billy beaker
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64623
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic