Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Assign response text from AJAX to a JSP tag attribute

 
Prabhat Kumar N
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using AJAX to get a string which I want to assign to a String attribute in custom JSP tag. For example,


Is there any direct or indirect way to achieve this ?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64613
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no way to achieve that. The JSP executes on the server, the Ajax request can;t be sent back to server until after the JSP finishes and the HTML page has been sent to the browser.

Please read this article to understand what JSP is and how it operates, and why what you are asking is impossible.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64613
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
P.S. If you need the result of a request while JSP is executing on the server, investigate the <c:import> tag.
 
Prabhat Kumar N
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:P.S. If you need the result of a request while JSP is executing on the server, investigate the <c:import> tag.


Yes. This will do. I went through <import> tag description. But how do I use the result of AJAX (xmlhttp.responseText) in the imported page Must I use something like this ?


How do I assign javascript value to c:param 's value ?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64613
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you use <c:import> you won't be using Ajax.
 
Prabhat Kumar N
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:If you use <c:import> you won't be using Ajax.


Actually, I am making a AJAX request sending form values to a servlet which processes and sends me a JSON object as string. I am want to use that JSON object in my custom tag. Is it possible to use c:import instead ?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64613
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<c:import> will simply grab whatever the response is. If it's JSON, then that's what you'll get.

At this point, just try it out.
 
Prabhat Kumar N
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:<c:import> will simply grab whatever the response is. If it's JSON, then that's what you'll get.

At this point, just try it out.


Thanks for helping me out so far.
I understand how it works. But the point is I need to send elements from the form to the servlet.

The flow looks like this

First I contact servlet.


The above code will return me a JSON string. I need to use this JSON string and send it as parameter to my page like this



Please let me know how ?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic