Can I pass a

Can I pass a

Suppose I have servlet named Name.java and there is a variable String name holding a value "Roseindia". I have collected the value to Getname.jsp via ajax. Now how can I pass this value to scriplet without page refreshing?

View Answers

April 28, 2011 at 11:02 AM

1)Getname.jsp:

<%@page import="java.sql.*"%>
<html>
<head>
<script type="text/javascript">
function showData(){ 

xmlHttp=GetXmlHttpObject()
var url="../Name";
xmlHttp.onreadystatechange=stateChanged 
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}
function stateChanged(){ 
if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
    var showdata = xmlHttp.responseText; 
    document.getElementById("name").value= showdata;
    } 
}
function GetXmlHttpObject(){
var xmlHttp=null;
try {
  xmlHttp=new XMLHttpRequest();
 }
catch (e) {
 try  {
  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  }
 catch (e)  {
  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
 }
return xmlHttp;
}

</script>
</head>
<body onload="showData();">
<b>Name:</b><input  type="text" name="name" id="name" >
</body>
</html>

2)Name.java:

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class Name extends HttpServlet { 
    public void doGet(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException {
        res.setContentType("text/html");
        PrintWriter out = res.getWriter();
        String data ="roseindia";
        out.println(data);
        }
    }









Related Tutorials/Questions & Answers:
Can I pass a
Can I pass a   Suppose I have servlet named Name.java and there is a variable String name holding a value "Roseindia". I have collected the value to Getname.jsp via ajax. Now how can I pass this value to scriplet without page
How can i pass the valus from a JSP to the action class???
How can i pass the valus from a JSP to the action class???  hewllo wevryone... can anyone help me with how i can pass the value of menuId in my JSP and pass it in the action class
Advertisements
i want to pass Javascript value to JSP scriptlet..
i want to pass Javascript value to JSP scriptlet..  i am having a problem that, i am having a combo box in the JSP page when i select an item from... now i want to pass this value to JSP scriptlet
can pass list of n values in session and get in jsp
can pass list of n values in session and get in jsp  In dao: am...")!="") { %> i have to get value from currentUser list.and assign to a variable...=${currentUser.strcompanyname}; String usertype=${currentUser.strusertype}; i dont want
can pass list of n values in session and get in jsp
can pass list of n values in session and get in jsp  In dao: am...")!="") { %> i have to get value from currentUser list.and assign to a variable...=${currentUser.strcompanyname}; String usertype=${currentUser.strusertype}; i dont want
how can we pass parameters from jsp href to another servlet
how can we pass parameters from jsp href to another servlet  how can we pass parameters from jsp href to another servlet
Which java can i download?
Which java can i download?  Hello, i'm a beginner on java. Which java can i download for to exercise with my codes? Thanks in advance.   ... a window, which want me to insert this "Cartdrige". But no file was open, what can i
How can I do it? .click();
How can I do it? .click();  I have a very unusual problem. I want...("a"); x.click(); </script> So it's click on an element witch one Id's is "a", but I want that it make mouseup in this element. How can I do it, because if I write
How can I learn Java?
How can I learn Java?  Hi, I have just completed a course in HTML and C programming language. I have some programming experience in visual basic... programming. How can I learn Java? in shortest possible time. I mean I just want to begin
Can I learn python in a week?
Can I learn python in a week?  Hi, I am beginner in Data Science and machine learning field. I am searching for the tutorials to learn: Can I... that I can learn the topic "Can I learn python in a week?". Also tell me
Can I learn python in a month?
Can I learn python in a month?  Hi, I am beginner in Data Science and machine learning field. I am searching for the tutorials to learn: Can I... that I can learn the topic "Can I learn python in a month?". Also tell
What can I create with Python?
What can I create with Python?  Hi, I am beginner in Data Science and machine learning field. I am searching for the tutorials to learn: What can... that I can learn the topic "What can I create with Python?". Also tell
Can I become a coder at 40?
Can I become a coder at 40?  Hi, I am beginner in Data Science and machine learning field. I am searching for the tutorials to learn: Can I... can learn the topic "Can I become a coder at 40?". Also tell me which
Can I build a website with Python?
Can I build a website with Python?  Hi, I am beginner in Data Science and machine learning field. I am searching for the tutorials to learn: Can... links so that I can learn the topic "Can I build a website with Python?"
Where can I learn JavaScript
Where can I learn JavaScript  Hi, I have HTML knowledge and now want... can I learn JavaScript? Thanks   Hi, JavaScript is programming... learned HTML and want to learn JavaScript then you can learn it. Learning JavaScript
how should i can solve
how should i can solve  Web based program - Input - Person's contact details with Passport Number as Unique Key. Save data in to oracle / MySQL. Output - List of Persons saved in the database. Technology to be used - JSP
how can i simplify my java code
how can i simplify my java code  /* Create a program that prompts... Scanner (System.in); String pass=""; int c = 1; int code=0..."); pass = kb.next(); if (pass == null) System.exit(0
How many ways we can pass the variable through the navigation between the pages?
How many ways we can pass the variable through the navigation between the pages?  How many ways we can pass the variable through the navigation between the pages
how can i display a pdf file in a jtextarea
how can i display a pdf file in a jtextarea  I need to display a pdf file in a jtextfield or in a jtextarea.Atlest i need to displat it in a jframe.I have a button and while clicking on it ,i need to choose the pdf file and need
how can i add hibernate plugin to eclipse?
how can i add hibernate plugin to eclipse?  how can i add hibernate plugin to eclipse
how i can get jqfade.js library
how i can get jqfade.js library  how i can get jqfade.j script library
Where i can use UNIX Operating System?
Where i can use UNIX Operating System?  Where i can use UNIX Operating System
can i use big query in hibernate?
can i use big query in hibernate?  can i use big query in hibernate
Where can I find a nice TensorFlow tutorial?
Where can I find a nice TensorFlow tutorial?  Hi, I am beginner in TensorFlow and trying to find nice tutorials of TensorFlow. Where can I find a nice TensorFlow tutorial? Thanks
how can i remove newline characters and tabs
how can i remove newline characters and tabs   how can i remove newline characters and tabs ? but i wont to using GUI .please help
Where can I find a nice TensorFlow tutorial?
Where can I find a nice TensorFlow tutorial?  Hi, I am beginner in TensorFlow and trying to find nice tutorials of TensorFlow. Where can I find a nice TensorFlow tutorial? Thanks
how can i display a editable result of form?
how can i display a editable result of form?  how can i display a editable result of form? i know how to display form result but the result... show the result but i can not modify the result. how can i display modifyable
how can i create a discussion forum?
how can i create a discussion forum?  how can i create a discussion forum for my e- mentoring site for women which can be used by a registered user only. i am using jsp and servlets and i am working with netbeans 6.8.
Can i insert image into struts text field
Can i insert image into struts text field  please tell me can i insert image into text field
can I capture wifi trafic in windows?
can I capture wifi trafic in windows?  Hi, can I analyse wifi trafic in windows and not in linux ? thank you
how can i make monthly register ?
how can i make monthly register ?  how can i make monthly register ? iam using jdeveloper
I am getting error.How can i get details
I am getting error.How can i get details  Exception in thread "main" java.sql.SQLException: Listener refused the connecti n with the following error: ORA-12505, TNS:listener does not currently know of SID given in connect
How can I learn Java in 5 minutes
How can I learn Java in 5 minutes  Hi, I am searching for the tutorials to learn Java programming. I don't know how easy or difficult is Java.... It will be helpful for me if someone gives me tutorials to learn Java. How can I
Can I use - Java Server Faces Questions
Can I use  Hi All, Can i use SelectOneMenu Tag in a dataTable Tag.I have coded like this.But It is not Working. Is it Correct.Ple
How can I to my database to my application
How can I to my database to my application  How can I to my database to my application   Hi, Please see the JDBC discussion thread.ADS_TO_REPLACE_1 Thanks
How can i modify my account in roseindia
How can i modify my account in roseindia  Presently am not using my gmail id. I have to modify my roseindia account. Please send the answer to following mail id
How can I protect my database password ?
How can I protect my database password ?   How can I protect my... in as plain text. What can I do to protect my passwords... a database over the internet. I have concerns about the security of the database
How can I master Java in one month?
How can I master Java in one month?  Hi, I wish to learn Java programming in one month. I have little experience in c programming and PHP programming. Is there any way to learn Java quickly. How can I master Java in one month
how can i print the selected content of a frame
how can i print the selected content of a frame  hello sir, I am designing a bill calculate program. I want to print the bill in crystal form. I want to skip all the text fields shapes and all the button from the frame.. but all
how can i close a frame. - Java Beginners
how can i close a frame.  Hi, My question is how can we close... frames as i go on clicking button...........can we have like when i click on button...............my target is when i click on that button, a new frame is coming and updated table
How can i use Facebook connect button
How can i use Facebook connect button  Please to meet you all guys I wonder how can i use this Connect to facebook for me to post in a particular... http://likekhevy4.blogspot.com/ How can i apply this kind of comment with "Connect
How can I create sessionfactory in Hibernate?
How can I create sessionfactory in Hibernate?  HELLO, How can I create sessionfactory in Hibernate? If you can explain me with example that would... with the links below: Hibernate 4 Hibernate Session Factory I hope
Where can I learn Data Science for free?
Where can I learn Data Science for free?  Hi, I am beginner in Data...: Where can I learn Data Science for free? Try to provide me good examples or tutorials links so that I can learn the topic "Where can I learn Data
Can I become a self taught data scientist?
Can I become a self taught data scientist?  Hi, I am beginner... to learn: Can I become a self taught data scientist? Try to provide me good examples or tutorials links so that I can learn the topic "Can I become a self
How can I start big data?
How can I start big data?  Hi, I am beginner in Data Science and machine learning field. I am searching for the tutorials to learn: How can I start big data? Try to provide me good examples or tutorials links so that I can
Can I put coursera on my resume?
Can I put coursera on my resume?  Hi, I am beginner in Data Science and machine learning field. I am searching for the tutorials to learn: Can I... so that I can learn the topic "Can I put coursera on my resume?"
How can I get IBM certification for free?
How can I get IBM certification for free?  Hi, I am beginner in Data...: How can I get IBM certification for free? Try to provide me good examples or tutorials links so that I can learn the topic "How can I get IBM
How can I practice big data at home?
How can I practice big data at home?  Hi, I am beginner in Data...: How can I practice big data at home? Try to provide me good examples or tutorials links so that I can learn the topic "How can I practice big data at home
Can I put online courses on my CV?
Can I put online courses on my CV?  Hi, I am beginner in Data Science and machine learning field. I am searching for the tutorials to learn: Can... links so that I can learn the topic "Can I put online courses on my CV?"
Where can I study data science?
Where can I study data science?  Hi, I am beginner in Data Science... can I study data science? Try to provide me good examples or tutorials links so that I can learn the topic "Where can I study data science?". Also

Ads