dcsimg
Passing values from javascript to servlet...
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Anonymous
Posted On:   Thursday, October 4, 2007 08:46 AM

Registration Page..... ]]>]]> Hai all,i have problem. I want to pass my values to servlet but those values are not passed to my servlet.First i want to explain my example,i write a javascript page with 4 text fields and three command buttons the first one is SAVE. When i click this button all entered data in text fields are send to servlet and those values i save in my database.But every time i get null.What is the problem any one pls help.Here i write code also FirstName Address DateOfBirth CusomerID > > >    More>>
Registration Page.....

Hai all,i have problem. I want to pass my values to servlet but those values are not passed to my servlet.First i want to explain my example,i write a javascript page with 4 text fields and three command buttons the first one is SAVE. When i click this button all entered data in text fields are send to servlet and those values i save in my database.But every time i get null.What is the problem any one pls help.Here i write code also
















FirstName

Address

DateOfBirth

CusomerID


>


>


>







My servlet name is custmorservlet,i pass the control to servlet through first button,but i don't get the text field data.Servlet code also i present here,


import javax.servlet.*;

import javax.servlet.http.*;

import java.io.*;

import java.sql.*;

public class CustmorServlet extends HttpServlet {

Connection con;

PreparedStatement st;

public void init(ServletConfig config) throws ServletException {

try {

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

con=DriverManager.getConnection("jdbc:odbc:custom","","");

}catch(Exception e) { }

}

public void doGet(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException {

String fn,add,db,ci;

fn=req.getParameter("fname");

add=req.getParameter("addr");

db=req.getParameter("dob");

ci=req.getParameter("cid");

res.setContentType("text/html");

PrintWriter out=res.getWriter();

try {

st=con.prepareStatement("insert into customer values(?,?,?,?)");

st.setString(1,fn);

st.setString(2,add);

st.setString(3,db);

st.setString(4,ci);

st.executeUpdate();

}catch(Exception e) { }

System.out.println("First name:"+fn);

out.println(" CustmorServlet ");

out.println("

one row is successfully added to database

");

out.println(" ");

}

public void destroy() {

try {

st.close();

con.close();

}catch(Exception e) { }

}

}

Basically i don't know much more about javascript and their tags.So any one pls solve my problem.


Advance thanxs........

   <<Less

Re: Passing values from javascript to servlet...

Posted By:   Stephen_McConnell  
Posted On:   Thursday, October 4, 2007 10:32 AM

If I am not mistaken, you are going to the parent location, but the action is not a "submit" action which puts the form elements into a "request" object.


If you want to do it the way you are doing, create a javascript function for each button that sets the "parent.location" field and then "submit()" the form.


Hope this helps.

About | Sitemap | Contact