JSP and AJAX

Discussions

Web tier: servlets, JSP, Web frameworks: JSP and AJAX

  1. JSP and AJAX (4 messages)

    Hi I like to use AJAX functionality in struts projects encapsulated in JSP tags. So, I don’t have to write the JavaScript Code or put JavaScript snippets in the JSP page. After searching the web I found the ‘Ajax JSP Tag’ Library http://ajaxtags.sourceforge.net/, but the project seemed to be stopped. What other JSP tag Libraries could you recommend? How do you use AJAX in JSP pages? Best regards Tobi

    Threaded Messages (4)

  2. Re: JSP and AJAX[ Go to top ]

    When you say you want to use AJAX, you need to write Javascript code, although not inside a JSP, but inside a JS file. Also, for what purpose do you want to use AJAX ? Let me assume some scenarios and tell you how AJAX will be of help. a) When the user clicks on a button or link etc, you want to display some additional data in the page. - Usually this is achieved by submiting the page, loading the data and displaying the page again with the data. - Using AJAX, when the user clicks the button, you can place a asynchronous request to the server for eg. to an obtaindata.do?somearg=someval etc...This is a normal struts action, which will do some processing and return to a jsp and the JSP prepares the HTML, and the controller writes the html to the response. Once this process is done, the 'callback' javascript function will be invoked, within this method, you have the ability to obtain the HTML returned by the server. It is responsibility of this javascript function to place this HTML at the appropriate place in your page. if you have used
    tags, then you can just say div.innerHTML=response.html etc.. Thus, what we achieved is some data is displayed to the user without submitting the whole page etc.. b) Validations - Assume a form where some data is entered, for eg. in the username textbox, user fills a username, and then user will continue to fill the rest of the form, meanwhile, during the onblur of the textbox, you can issue a asynchronous request to validate the username to check if such username already exists in the database, and if it exists, then immediately an alert could be displayed to the user accordingly. c) Dynamic Data - for eg. You have two dropdowns 1) Country dropdown 2) Cities dropdown, thus when the user selects a country, then in the onchange event, you can issue a AJAX request to obtain all the cities of the country and populate the Cities dropdown. refer to http://www.w3schools.com/ajax/ajax_intro.asp to write the AJAX methods and related application specific callback methods.
  3. Re: JSP and AJAX[ Go to top ]

    Thank you for your answer. I like to use AJAX for Autocomplete, Select/dropdown, Tab Panel, etc. (see http://ajaxtags.sourceforge.net/). I don't agree with your opinion that I have to write JavaScript code to use AJAX. What about Google? With GWT I think you don't have to write JavaScript? Regards Tobi
  4. Re: JSP and AJAX[ Go to top ]

    Hi Tobi, I am also analyzing different frameworks based on AJAX... Did you try GWT? Can you please share your experience with this open source tool? Regards, Purvesh
  5. Re: JSP and AJAX[ Go to top ]

    There are lot of Ajax components in Coldtags suite: http://www.servletsuite.com/jsp.htm#ajax