Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Spring Framework | Web Services | BioInformatics | Java Server Faces | Jboss 3.0 tutorial | Hibernate 3.0 | XML

Tutorial Categories: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML

Fresher Job


 

Search Host

Monthly Fee($)
Disk Space (MB)
Register With us for Newsletter!
Visit Forum! Post Questions!
Jobs At RoseIndia.net!

Have tutorials?
Add your tutorial to our Java Resource and get tons of hits.

We offer free hosting for your tutorials. and exposure for thousands of readers. drop a mail
roseindia_net@yahoo.com
 
   

Tutorials

Java Server Pages

JAXB

Java Beans

JDBC

MySQL

Java Servlets

Struts

Bioinformatics

Java Code Examples

Interview Questions

 
Join For Newsletter

Powered by groups.yahoo.com
Visit Group! Post Questions!

Web Promotion

Web Submission

Submit Sites

Manual Submission?

Web Promotion Guide

Hosting Companies

Web Hosting Guide

Web Hosting

Linux

Beginner Guide to Linux Server

Frameworks

Persistence Framework

Web Frameworks

Free EAI Tools

Web Servers

Aspect Oriented Programming

Free Proxy Servers

Softwares

Adware & Spyware Remover

Open Source Softwares

struts(DWR)
Expert:dileep
i want to pass a combo box value from my jsp page to servlet . where i had to done this by using DWR.. It is getting null value into servlet.


i.e, i am giving my sample code here! plz help me ,



my.jsp::::: jsp page

<html>
<head>
<script type="text/javascript">
var xhr;

function modifyPage() {

try {
xhr = new ActiveXObject("Msxml2.XMLHTTP");
//alert("Msxml2.XMLHTTP ActiveXObject created");
} catch (e) {
try {
xhr = new ActiveXObject("Microsoft.XMLHTTP");
//alert("Microsoft.XMLHTTP ActiveXObject created");
} catch (E) {
xhr = false;
}
}

if (!xhr && typeof XMLHttpRequest != 'undefined') {
xhr = new XMLHttpRequest();
//alert("XMLHttpRequest Object created");
}

xhr.open("GET", "../message", "true");
//alert("Open method called");
xhr.setRequestHeader("User-Agent", "my browser");
//alert("Request header setted");

//here is the actual problem

var queryString ="name=value&anothername=othervalue&so=on";
xhr.send(queryString);

// the values of name and others are getting as "null" in servlet

xhr.onreadystatechange=function()
{
//alert("State : " + xhr.readyState + "" );
if (xhr.readyState != 4) return;
if(xhr.status==200)
{
alert("The document will change now" );
var r=xhr.responseText;
t=r.split(',');
//alert(t);
//document.getElementById("message").innerHTML = xhr.responseText;
//some work on retrieved message. it able to retrieve message here.
}//if
else
{
document.getElementById("items").innerHTML = "ur browser doestnot support ajax";
}
}

xhr.send(null);

}
</script>
</head>
<body>
<form name="form1">

<b>Classes</b>
<input type="text" name="item1" size="45">
<br>
<select name="classes" Id="classes" onChange="modifyPage();">
<option>we</option>
<option>are</option>
<option>here</option>
<option>fru</option>
</select>
<div ID="items">
<input type="hidden" id="add"/>
</div>
<input type="button" value="create"/>
</form>
</body>
</html>






myservlet.java:


import java.io.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import javax.servlet.*;
import javax.servlet.http.*;

public class MessageServlet extends HttpServlet {

private ServletContext context;
private String sub_classes=null;

public void init(ServletConfig config) throws ServletException {
this.context = config.getServletContext();

}

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {

response.setContentType("text/plain");
response.setHeader("Cache-Control", "no-cache");


String DriverName = "com.mysql.jdbc.Driver";
String ConnectionURL = "jdbc:mysql://localhost:3306/test";
String UserName = "root";
String Password = "root";

//actual probleh is here

String s=(String)request.getParameter("name");
System.out.println("here see me "+s);

//the above string "s" is printing as null on console of server.
// how to get the value of the name or other variables.here

String Classes_Sale_Display="SELECT * FROM customers where username='"+username+"'";
PreparedStatement pstmt = null;


try {
Class.forName(DriverName);
Connection con = DriverManager.getConnection(ConnectionURL,UserName,Password);
pstmt = con.prepareStatement(Classes_Sale_Display);
ResultSet rs = pstmt.executeQuery ();

while (rs.next())
{
//price=0;
sub_classes =rs.getString("availTraining");
System.out.println(sub_classes);
}
response.getWriter().write(sub_classes);

}//try
catch (Exception e) {
System.out.println(e);
}

}

public void doPost(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {

response.setContentType("text/plain");
response.setHeader("Cache-Control", "no-cache");
response.getWriter().write(sub_classes);

}
}

I am able to pass the control to the servlet through the above code , my only problem here is to get the values from jsp to servlet using xhr.send(); please correct the code and help me

i have been working on it for the last 3 days,

thanks in advance.

Answers
More Questions
Post Answers
 
Ask Question Facing Programming Problem?
Useful Links
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification

Tell A Friend
Your Friend Name
Search Tutorials

 

 
 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2007. All rights reserved.