JSP JavaScript integration taglib ver. 1.3  Hot PDF Print E-mail
Tag it:
Delicious
Furl it!
Digg
NewsVine
Reddit
YahooMyWeb
Technorati
Articles Reviews JSP
Written by Phil Harrison   
Sunday, 18 February 2007

{mos_sb_discuss:34}

Custom JSP tag helps you implement some programming tricks in Ajax style. This taglib lets you integrate JSP and JavaScript. Right from your JavaScript code you will be able to call server-side stuff (JSP, servlet) with the same idea - update the part of your screen without the reloading the whole page.

 



More precisely tag  jscall  lets you create a GET HTTP request to your server-side. Technically this tag defines JavaScript function that will implement HTTP request. Because you are calling from JavaScript your server side must return JavaScript too.

It could be just a chunk of JavaScript code added to your page (e.g. some set of functions you will call later) or a real JavaScript call.

For example from our JavaScript code (main page) we are going to call a JSP file that will update the label for the clicked button on the main page:  

<%@ taglib uri="taglib.tld" prefix="j" %>

<j:jscall name="f" url="test.jsp"/>

<form>
  <input name="b1" type="button" value="Test" onClick="f('Tested')">
</form>

here tag tag jscall defines a function f. Any call for this function will cause GET request to file test.jsp. Arguments will be passed in the query string. So your test.jsp file looks so:  

 document.forms[0].b1.value='<%=request.getQueryString()%>';

Note: you do not need <script> brackets in this file!
 
Read more 


User reviews

There are no user reviews for this item.

Add new review




Powered by jReviews

Last Updated ( Thursday, 05 July 2007 )
 
< Prev   Next >