• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

html form,servlet

 
krishna bhargavi
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Below is my servlet code and HTML code.After submiting the form it has to go to servlet and it will take the form data and it has to insert the form data into databae.
but its not working.after submiting the form it is not going to servlet page.please help me.All these i am doing in Eclipse IDE.

HTML code:

<html>
<head>

<title> Sign Up </title>

<link rel="stylesheet" type="text/css" href="css/signup.css">

</head>

<body style="margin-bottom:-101px;">

<div class="wrapper">
<div class="header"> Doubts? Questions?
<span class="orangeheadertext">Call Now on 9581799999</span>
or text
<span class="orangeheadertext"> UNIXELL to *55555</span>
<span class ="rightheader"> User Login </span>
<span class ="lineBar"> New User?</span>

<span class="signup"> Sign Up </span>
<span class="spantext"> Help </span>
<span class ="lineBar"> </span>
<span class="spantext"> FAQs </span>
</div>

<div class="menu">






</div>

<div class="sign" id="signupform">

<form action="servlet/Loginservlet" method="post" >

Create your Account:



<label for="username" accesskey="u" style="padding-left:3px;">User Name: </label>

<input type="text" style="background-color:#ffffff;margin-left:14px;padding-top:7px;border-width:0px;margin-top:6px;padding-right:85px;" id="username" name="username" tabindex="1">



<label for="password" accesskey="p" style="padding-left:4px;">Password: </label>

<input type="password" style="background-color:#ffffff;margin-left:14px;padding-top:7px;border-width:0px;padding-right:85px;" id="password" name="pasword" tabindex="2">



<label for="confirmpassword" accesskey="c" style="padding-left:5px;">Confirm Password: </label>

<input type="password" style="background-color:#ffffff;margin-left:14px;padding-top:7px;border-width:0px;padding-right:85px;" id="confirm" name="confirm" tabindex="3">



<label for="email" accesskey="e" style="padding-left:5px">Email: </label>

<input type="text" style="background-color:#ffffff;margin-left:14px;padding-top:7px;border-width:0px;padding-right:85px;" id="email" name="email" tabindex="4">



<label for="firstname" accesskey="f" style="padding-left:3px;">First Name: </label>

<input type="text" style="background-color:#ffffff;margin-left:14px;padding-top:7px;border-width:0px;padding-right:85px;" id="firstname" name="firstname" tabindex="5">



<label for="lastname" accesskey="l" style="padding-left:4px;">Last Name: </label>

<input type="text" style="background-color:#ffffff;margin-left:14px;padding-top:7px;border-width:0px;padding-right:85px;" id="lastname" name="lastname" tabindex="6">



<label for="companyidentifier" accesskey="ci" style="padding-left:5px;">Company Identifier: </label>

<input type="text" style="background-color:#ffffff;margin-left:14px;padding-top:7px;border-width:0px;padding-right:85px;" id="identifie" name="identifier" tabindex="7">



<label for="company" accesskey="e" style="padding-left:5px">Company: </label>

<input type="text" style="background-color:#ffffff;margin-left:14px;padding-top:7px;border-width:0px;padding-right:85px;" id="company" name="company" tabindex="8">



Postal Address:


<label for="address1" accesskey="ad" style="padding-left:5px">Address1:</label>

<input type="text" style="background-color:#ffffff;margin-left:14px;padding-top:7px;border-width:0px;padding-right:85px;" id="addr" name="addr" tabindex="9">



<label for="address2" accesskey="ad1" style="padding-left:5px">Address2:</label>

<input type="text" style="background-color:#ffffff;margin-left:14px;padding-top:7px;border-width:0px;padding-right:85px;" id="addr1" name="addr1" tabindex="10">



<label for="city" accesskey="ct" style="padding-left:5px">City:</label>

<input type="text" style="background-color:#ffffff;margin-left:14px;padding-top:7px;border-width:0px;padding-right:85px;" id="city" name="city" tabindex="11">



<label for="state" accesskey="s" style="padding-left:5px">State:</label>

<input type="text" style="background-color:#ffffff;margin-left:14px;padding-top:7px;border-width:0px;padding-right:85px;" id="state" name="state" tabindex="12">



<label for="zipcode" accesskey="z" style="padding-left:5px">Zipcode:</label>

<input type="text" style="background-color:#ffffff;margin-left:14px;padding-top:7px;border-width:0px;padding-right:85px;" id="zip" name="zip" tabindex="13">



<label for="country" accesskey="cnt" style="padding-left:5px">Country:</label>

<input type="text" style="background-color:#ffffff;margin-left:14px;padding-top:7px;border-width:0px;padding-right:85px;" id="country" name="cuntry" tabindex="14">



<label for="telephone number1" accesskey="" style="padding-left:5px">Mobile Number:</label>

<input type="text" style="background-color:#ffffff;margin-left:14px;padding-top:7px;border-width:0px;padding-right:85px;" id="mobno" name="mobno" tabindex="15">



<label for="telephone number2" accesskey="ad" style="padding-left:5px">Telephone Number:</label>

<input type="text" style="background-color:#ffffff;margin-left:14px;padding-top:7px;border-width:0px;padding-right:85px;" id="telno" name="telno" tabindex="16">



<label for="fax" accesskey="fx" style="padding-left:5px">Fax:</label>

<input type="text" style="background-color:#ffffff;margin-left:14px;padding-top:7px;border-width:0px;padding-right:85px;" id="fax" name="fax" tabindex="17">



<input type="submit" value="Submit" style="margin-left:164px;"/>

<input type="reset" value="Reset" style="margin-left:17px;"/>

</form>

</div>

</div>

</body>

</html>

My Servlet code:



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

public class Loginservlet extends HttpServlet {

public void doPost(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException
{
String connectionURL = "jdbc:mysql://localhost:3306/mysql";
Connection connection=null;
res.setContentType("text/html");
PrintWriter out = res.getWriter();
String username= req.getParameter("username");
String password = req.getParameter("password");
try {
Class.forName("com.mysql.jdbc.Driver");
connection = DriverManager.getConnection(connectionURL, "root", "root");
String sql = "insert into signup values (?,?)";
PreparedStatement pst = connection.prepareStatement(sql);
pst.setString(1, username);
pst.setString(2, password);

int numRowsChanged = pst.executeUpdate();
out.println(" Data has been submitted ");

pst.close();
}
catch(ClassNotFoundException e){
out.println("Couldn't load database driver: "+ e.getMessage());
}
catch(SQLException e){
out.println("SQLException caught: " + e.getMessage());
}
catch (Exception e){
out.println(e);
}
finally {
try {
if (connection != null)
connection.close();
}
catch (SQLException ignored){
out.println(ignored);
}
}
}
}






 
krishna bhargavi
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
please help me anyone.....
 
Rob Spoor
Sheriff
Pie
Posts: 20372
44
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
PatienceIsAVirtue. And please UseCodeTags; you can add them to your post by editing it. Select "XML" for the HTML code and "Java" for the Java code.
 
Nitin Surana
Ranch Hand
Posts: 129
Java Netbeans IDE Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
and how does your web.xml look? Have you registered your servlet in web.xml?
 
Kumaravadivel Subramani
Ranch Hand
Posts: 171
Java Linux Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you registered/mapped your servlet against the proper URL pattern? Post your web.xml here for further..
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic