Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Ajax Can I pass a
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Paritosh Das
Can I pass a
1 Answer(s)      3 years and 8 months ago
Posted in : Ajax


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?


Advertisement
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
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
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
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
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 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 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
can i use big query in hibernate?
can i use big query in hibernate?  can i use big query in hibernate
Where i can use UNIX Operating System?
Where i can use UNIX Operating System?  Where i can use UNIX Operating System
how i can get jqfade.js library
how i can get jqfade.js library  how i can get jqfade.j script library
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 can i make monthly register ?
how can i make monthly register ?  how can i make monthly register ? iam using jdeveloper
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 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
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.
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. Thanks
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 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 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 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 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 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 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
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 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
 

 

 

DMCA.com