jquery ajax and servlet

jquery ajax and servlet

hi.. i am using jquery,ajax and servlet in ma application.On the webpage when user selects id from the drop downbox and ckicks on "show person " button i am calling a servlet "GetPerson" through ajax inside this servlet i have set some session variables "myID" n "name"...when it returns back to the ajax function i load hello.jsp file in the

tag but in hello.jsp everytime i access the session variable "myID" the value is same irrespective of the id selected in the dropdown. m posting ma code here

//models/People.java package models;

public class People {

private String people[] 
         = new String[] { "Bob", "Bill", "Jan", "Ellen", "Ken", };
  public int getNumPeople() { return people.length; }
  public String getPerson(int num) { return people[num]; }

}

//servlet/GetPerson.java

package servlet;

import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession;

import java.io.*; //import javax.servlet.ServletException; //import javax.servlet.http.*; import models.People; /** * Servlet implementation class GetPerson */ @WebServlet("/GetPerson") public class GetPerson extends HttpServlet { private People people = new People();

protected void processRequest(
        HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
     System.out.println("inside servlet");
    HttpSession session = request.getSession(true);
    response.setContentType("text/html;charset=UTF-8");
    PrintWriter out = response.getWriter();

    try {
      String id = request.getParameter("id");
      session.setAttribute("myName",id );
      System.out.println(session.getAttribute("myName"));
      out.print(people.getPerson(Integer.parseInt(id)));
      session.setAttribute("name1",people.getPerson(Integer.parseInt(id)));
    } finally {
      out.close();
    }

}

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    // TODO Auto-generated method stub
    processRequest(request,response);
}

}

//index.jsp <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <%@ page import="java.util.*" %> <%@ page import="models.*" %> Selection with JavaScript Display

AJAX "get person"

<select id="sel">
  <% for( int i = 0; i < people.getNumPeople(); ++i ) { %>
  <option value="<%=i%>"><%=i%></option>
  <% } %>
</select>
<button id="button">Show Person</button>
<br /><br />
Selected person: <span id="out"></span><span id="out1"></span>

//hello.jsp <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> Insert title here <% String id =(String)session.getAttribute("myName"); out.print("hi:"+id); session.removeAttribute("myName"); {%>

<%=id%>

<%} %>

try jquery name<%=id%>

anyone plz tell me how could i do this??? thanks alot!!

View Answers









Related Tutorials/Questions & Answers:
jquery ajax and servlet
jquery ajax and servlet  hi.. i am using jquery,ajax and servlet... and ckicks on "show person " button i am calling a servlet "GetPerson" through ajax inside this servlet i have set some session variables "myID" n "name"...when
Ajax in jQuery
Ajax in jQuery  How ajax can be use in JQuery?   Given below the code for ajax in jquery: $(document).ready(function() { $('#form').submit(function(){ var number = $('#number').val(); $.ajax({type:"post",url
Advertisements
jQuery ajax get example
jQuery ajax get example  Hi, How I can use jQuery for get request? Give me code for jQuery ajax get request. Thanks
jQuery Ajax load request
jQuery Ajax load request  Hi, How to use jQuery to send the request on server to load data in web page? Thanks   Hi, In the jQuery Load Content tutorial you will find the code example to send request on server
jQuery ajax json
jQuery ajax json  Hi, How to use jQuery to load json data through Ajax request? Thanks   Hi, In Java you can use the following code to crate the json response: JSONObject obj=new JSONObject(); obj.put("name","foo
How to use Servlet and Ajax?
How to use Servlet and Ajax?  How to use Servlet and Ajax
application using AJAX and JQuery and also use JSP
application using AJAX and JQuery and also use JSP   i need create an application using AJAX and JQuery and also use JSP
jquery - JSP-Servlet
://www.roseindia.net/ajax/jquery/ Hope that it will be helpful for you. Thanks...jquery  Hi, I need validation script for jquery. I have username... jquery with jsp. Please send the code for me immediately. Regards
JQuery-JSP AJAX example not working
JQuery-JSP AJAX example not working  Hi, I while back ran you tutorial at http://www.roseindia.net/tutorial/jquery/jqSquareroot.html. I copied... started with AJAX)), I was able to get it working. Just recently, I have been
How to send data by ajax to servlet? - Ajax
How to send data by ajax to servlet?  Hi, Can i send a value from a HTML file to servlet via Ajax? If it is possible please give me a sample code Thanks
how to done calculation for dynamic generated textboxes in jquery/javascript/ajax?
how to done calculation for dynamic generated textboxes in jquery/javascript/ajax?  how to done calculation for dynamic generated textboxes in jquery/javascript/ajax
Ajax+servlet+js
Ajax+servlet+js  1) new.jsp <%@ page language="java...-Type" content="text/html; charset=ISO-8859-1"> <title>Simple AJAX... in 1st text box,after click on button i must get value from servlet in 2nd text
ajax and servlet - Java Beginners
ajax and servlet  Pls do this favour... How can we chat with 2computers using ajax programing and servlets when internet is connected
i want horizontal mlm tree structure code in php with jquery or Ajax
i want horizontal mlm tree structure code in php with jquery or Ajax  i need horizontal mlm tree structure code in php with jquery or Ajax... in advance.. Thank you
Ajax validation - JSP-Servlet
Ajax validation  How to fade out the images when an onblur function is called moving from a text box to another?? can anyone help out with with the code
Ajax - JSP-Servlet
Ajax  Simple ajax code for getting one text box value  Hi friend, Code to help in solving the problem : function postRequest... on Ajax visit to : http://www.roseindia.net/ajax/ Thanks
jsp and ajax - JSP-Servlet
jsp and ajax  i had some problem i want to display the current system date and time in each and every page of my project just i want the time to be automatically updated for every second for that i want to make an ajax call
Crop image Using JQuery, servlet or JSP.
Crop image Using JQuery, servlet or JSP.  Hi sir I need the code of Cropping image using JQuery with the help of servlet or JSP. I need both the code Client side as well as of server side. Please Help me
ajax in java - JSP-Servlet
ajax in java  The below code is for a php page but I want this in JSP page. function postRequest(strURL){ var xmlHttp; if(window.XMLHttpRequest){ // For Mozilla, Safari, ... var xmlHttp = new XMLHttpRequest
how can i use ajax and jquery in netbeans ide
how can i use ajax and jquery in netbeans ide  i am using .net here we hav to download ajax controls and if i use netbeans ide and uses ajax control so from where i can get these controls.also i want to know which struct book i
How to add google page in my webpage using jquery ajax.
How to add google page in my webpage using jquery ajax.  Hi, I...://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> <script type="text/javascript"> $(document).ready(function() { $.ajax({ url
How to save form data to a csv file using jquery or ajax
, Thank you for your reply , i am suppose to use only jquery or ajax for doing...How to save form data to a csv file using jquery or ajax  Please let...=data.responseText; Now the problem is ,i should write form data to a csv file using ajax
Ajax
Ajax  how to impliment ajax in registration table using jsp-servlet
jQuery Training
developing Ajax based application. In this jQuery training we will provide you many examples that you can use in your project. This training covers jQuery Ajax... Using jQuery for Ajax request a) jQuery post form b) jQuery get
JQuery
), textbox is in one jsp file, the ajax mathod call should be in another jsp file, use jquery autocomplete
Login through database with the help of jQuery 'ajax' & JSP
Login through database with the help of jQuery 'ajax' & JSP In this tutorial, we will discuss about how to use ajax function of jQuery to create.... In this example , login page contain jQuery ajax to make connection with JSP ,which
JQuery
), textbox is in one jsp file, the ajax mathod call should be in another jsp file using url of the doctors, use jquery autocomplete
JQuery
JQuery  how to use jquery
jQuery questions - Ask jQuery questions
;jQuery Features Ajax library CSS Manipulation from jQuery code Events...://www.roseindia.net/ajax/jquery/index.shtml.  ADS_TO_REPLACE_4...jQuery questions - Ask jQuery questions   
Ajax with jQuery Example
Ajax with jQuery Example
AJAX with jQuery Example
Ajax with java(using Dojo) - JSP-Servlet
Ajax with java (using Dojo)  Hi, In In place Edit Box,when I click "save" button how can I save the data in server side i.e JSP or how can I call.... Is there a possibility for tutorial on Scriptaculous. us,for Java programmers
What is jQuery?
What is jQuery?       jQuery is great library for developing ajax based application. jQuery is great... applications. You can use jQuery to develop cool web 2.0 applications. jQuery
problem getting servlet:xmlHTTP.status=404 - Ajax
problem getting servlet:xmlHTTP.status=404   hi, ihave a text field... object.The problem is my script is unable to get the servlet in which i have... of the servlet, it gets it and teh xmlHTTP.status =404 condition becomes false.im using
Jquery
Jquery  I am new to Jquery. Can anyone please tell me how to use jquery plugins in html
jquery
jquery  What are the Jquery similarities or difference with other java script libraries
learn jquery
learn jquery   is it possible to learn myself jquery,ajax and json   Yes, you can learn these technologies by yourself. Go through the following links: Ajax Tutorials JSON Tutorials JQuery Tutorials
learn jquery
learn jquery   is it possible to learn myself jquery,ajax and json   Yes, you can learn these technologies by yourself. Go through the following links: Ajax Tutorials JSON Tutorials JQuery Tutorials
JQuery
JQuery  How i begin JQuery and where i begin learning?   Please visit the following link: JQuery Tutorials Learn Jquery from the above link. Here you will get lot of examples with illustration
jQuery 'serialize' Ajax shorthand method
jQuery 'serialize' Ajax shorthand method In this tutorial , jQuery 'serialize' method is implemented to create query for set of form.... It could be sent to a server in an Ajax request. serializeMethod.html
ZF Ajax Setup
ZF and Ajax: We assume that you have a fair knowledge over Ajax but let's have a quick look: As we all know that Ajax is an acronym for Asynchronous... in Ajax, use the XMLHttpRequest object. JavaScript:  The key component
jQuery
jQuery  Hi, What is jQuery and how it is used to develop Web applications? Thanks
jquery
jquery  how to display the leaves taken or holidays of the year or half working days in a calendar in some colors to identify the days using jquery plugin
JQuery
JQuery  hi there, I am just beginner for jQuery and i want to know-what is jQuery ? How it is better than JavaScript ?   jQuery... JavaScript : Each jQuery returns itself so you can chain them together(Chaining
jQuery Demos
database with the help of jQuery 'ajax' & JSP... database using JSP jQuery 'serialize' Ajax shorthand...://www.roseindia.net/tutorial/ajax/jquery/index.html ADS_TO_REPLACE_1
JQuery
JQuery  how to create jquery auto-complete textbox ? in which data come from database table?   Please visit the following link: http://www.roseindia.net/tutorial/jquery/autoSuggestTextbox.html   thank you
jQuery Training Course
There are many Ajax framework but jQuery is very easy to use. You can use... to submit form Using jQuery with PHP, JSP, Servlet and ASP.NET jQuery... jQuery Training Course    
ajax
ajax  How can we fetch data in ajax through servlet?   "mainpage.jsp" <html> <head> <title>Ajax Example</title>...;/head> <body> <h1 align="center"><font color="#000080">Ajax
ajax
ajax  How can we fetch data in ajax through servlet?   "mainpage.jsp" <html> <head> <title>Ajax Example</title>...;/head> <body> <h1 align="center"><font color="#000080">Ajax

Ads