• Post Reply Bookmark Topic Watch Topic
  • New Topic

jsp javascript doubt with regard to form fields

 
paddy Mahadeva Iyer
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have written a javascript that creates textboxes dynamically according to user clicks using "innerHTML". But I have now encountered a problem. I have a <jsp:param> and a <jsp:include> tag that also must be part of the string in innerHTML that genrates the field. But this I am not able to do. Can somebody suggest a workaround for this.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is important to understand that JSP and Javascript code are interpreted in two different places.

JSP is interpreted first and on the server.
It writes the HTML and Javascript.
When it is done it streams the HTML and Javascript to the browser.

At this point, the browser starts to interpret your HTML and javascript.
The server is finished and the connection between the two is severed.
No more JSP code will be interpreted.

For this reason, it is fundamentally impossible to to write JSP code with Javascript.


The best way to get your head around this is to get in the habit of viewing the HTML source from your browser. When you do this, you will see the result s rendered by your JSP. This is what the browser sees.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65520
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After reading Ben's excellent explanation, you might find this article helpful.

And once you understand all that, you could look into using Ajax to (sort of) simulate a client-side equivalent of a JSP include.
 
paddy Mahadeva Iyer
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guyz,

thanks a lot. I knew that ajax could solve my problem . I posted it here simply because i find that i can write scriptlets but not tags that raised the issue in my mind.
I think I have a lot to learn in JSP. Thanks a lot!
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Scriptlets are no different than tags in this respect.

No server side code can be executed in response to client side events; not without creating a new request (AJAX) anyway.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!