What's wrong with my form?

What's wrong with my form?

Dear expert,

I'm having trouble with my enquiry form.

Hope you can tell me where my mistake lies.

Thanks.

Here's my jsp code:

<title>Enquiries</title>
<link rel="stylesheet" type="text/css" href="stylesheet.css" media="screen,projection" />
<link rel="stylesheet" style type ="text/css" href ="style.css">
<script type="javascript">


var objForm = new Object();
var strName = new Object();
var strEmail = new Object();
var strContact = new Objec();
var strEnquiry = new Object();

objForm = document.getElementById("frmData");
objName = document.getElementById("name")
objEmail = document.getElementById("e-mail");
objContact = document.getElementById("contact");
objEnquiry = document.getElementById("enquiry");

strName = objName.value;
strEmail = objEmail.value;
strEnquiry = objEnquiry.value;

</script>
<div id="container">

<div id="content">
<form id="frmData" name="frmData" action="ProcessEnquiry" method="post" >

<h2><strong>Enquiry Form</strong></h2>
<fieldset>
<p><label for="name">Name:</label></br> <input type="text" name="name" id="name" /></p>
<p><label for="e-mail">E-mail:</label></br> <input type="text" name="e-mail" id="e-mail" /></p>
<p><label for="contact">Contact No:</label></br> <input type="text" name="contact" id="contact" /></p>

<h3>Your Enquiry:</h3>

<br />
<textarea name="enquiry" rows="8" cols="65"></textarea>
<br/>
<input type="submit" value="Submit" />
</form>
</div>
</fieldset>

</div>

And here's my servlet codes:-

public class ProcessEnquiry extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");

PrintWriter out = response.getWriter();
Connection con = null;
ResultSet rs = null;
PreparedStatement ps = null;
Statement stmt = null;
String strName = "";
String strEmail = "";
String strContact = "";
String strEnquiry = "";
String strMessage = "";
String strCreateRecordSQL = "";
try {
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost/tangara_member", "tangara_karen", "123");

strCreateRecordSQL = "INSERT INTO enquiry";
strCreateRecordSQL += "(strName, strEmail, strContact, strEnquiry + VALUES (?,?,?,?)";
ps.executeUpdate();
out.println("Your mail is sent");
strMessage= "<a href=\"index.jsp\">Click here to return to Home Page";
} catch (SQLException e) {
throw new ServletException("Servlet could not display records", e);
} catch (ClassNotFoundException e) {
throw new ServletException("JDBC Driver Not Found", e);
} finally {
try {
if (rs != null) {
rs.close();
rs = null;
}
if (stmt != null) {
stmt.close();
stmt = null;
}
if (con != null) {
con.close();
con = null;
}
} catch (SQLException e) {
throw new ServletException("Servlet could not display records", e);
}
}
out.close();
}
}

My database :

strName text
strEmail text
strContact text
strEnquiry BLOB

Many thanks
View Answers

July 21, 2010 at 1:29 PM

Hi Friend,

Try the following code:

1)index.jsp:

<html>
<title>Enquiries</title>
<link rel="stylesheet" type="text/css" href="stylesheet.css" media="screen,projection" />
<link rel="stylesheet" style type ="text/css" href ="style.css">
<div style="width:680px; margin:0 auto; height:320px; padding:10px 0; border:solid; position:relative;">
<form id="frmData" name="frmData" action="../ProcessEnquiry" method="post" >
<h2><strong>Enquiry Form</strong></h2>
<table>
<tr><td>Name:</td><td><input type="text" name="name" id="name" /></td></tr>
<tr><td>E-mail:</td><td><input type="text" name="email" id="email" /></td></tr>
<tr><td>Contact No:</td><td><input type="text" name="contact" id="contact" /></td></tr>
<tr><td>Your Enquiry:</td><td><textarea name="enquiry" rows="8" cols="65"></textarea></td></tr>
<tr><td></td><td><input type="submit" value="Submit" /></td></tr>
</table>
</form>
</div>
</html>

2)ProcessEnquiry.java:

import java.io.*;
import java.sql.*;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class ProcessEnquiry extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");

PrintWriter out = response.getWriter();
String strName = request.getParameter("name");
String strEmail =request.getParameter("email");
String strContact = request.getParameter("contact");
String strEnquiry = request.getParameter("enquiry");

try {
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost/mysql";, "root", "root");
PreparedStatement pst=con.prepareStatement("insert into enquiry(name,email,contact,enquiry)values(?,?,?,?)");
pst.setString(1,strName);
pst.setString(2,strEmail);
pst.setString(3,strContact);
pst.setString(4,strEnquiry);
pst.executeUpdate();
out.println("Your mail is sent");
out.println("<a href=\"index.jsp\">Click here to return to Home Page");
} catch (Exception e) {
System.out.println(e);
}
}
}

Thanks









Related Tutorials/Questions & Answers:
What is wrong with my servlet?
what is wrong with my JSP codes for updating a form?
Advertisements
What's wrong with my form? - Java Beginners
What's wrong with my pagination code in JSP?
What is wrong with this line
what is wrong with this program
what is wrong in this program
what is wrong in this program......
ModuleNotFoundError: No module named 'formv'
ModuleNotFoundError: No module named 'formy'
ModuleNotFoundError: No module named 'forml'
Not sure whats wrong with my code HELP PLEASE?!?!
What are different normalization forms?
please check my code is wrong or ok.it was not work .this is form validation in javascript using jsf page
ModuleNotFoundError: No module named 'odoo10-addon-account-invoice-pro-forma-sequence'
ModuleNotFoundError: No module named 'odoo10-addon-account-invoice-pro-forma-sequence'
please check my code is wrong or ok.it was not work .this is form validation in javascript using jsf page
what is wrong in this program?I have netbeans 7.0 & jdk 7. please do corrections.
What is the best way to learn Java on my own?
ModuleNotFoundError: No module named 'wrong'
wrong year
What should I study on my own to become a data scientist?
I really hate my data scientist job. What's your experience?
swing components are not running in my system what to do now??
use forms.
what timing attack {practically}??? any one can help me in my Ph.d thesis
Please tel me .In my System Oracle9i and J2sdk1.6 are Installed.Why this problem occures and what is the solution?
Sql aggregate function with left join wrong output
Sql aggregate function with left join wrong output
Sql aggregate function with left join wrong output
ModuleNotFoundError: No module named 'aldryn-forms'
ModuleNotFoundError: No module named 'aldryn-forms'
ModuleNotFoundError: No module named 'aldryn-forms'
ModuleNotFoundError: No module named 'capybara-forms'
ModuleNotFoundError: No module named 'cms-forms'
ModuleNotFoundError: No module named 'Constellation-Forms'
ModuleNotFoundError: No module named 'djangocms-forms'
ModuleNotFoundError: No module named 'dynamic-forms'
ModuleNotFoundError: No module named 'forms_extras'
ModuleNotFoundError: No module named 'google_forms'
ModuleNotFoundError: No module named 'manhattan-forms'
ModuleNotFoundError: No module named 'needle-forms'
ModuleNotFoundError: No module named 'normal-forms'
ModuleNotFoundError: No module named 'normal-forms'
ModuleNotFoundError: No module named 'omero-forms'
ModuleNotFoundError: No module named 'pulpo-forms'
ModuleNotFoundError: No module named 'pulpo-forms'
ModuleNotFoundError: No module named 'pyoracle-forms'
ModuleNotFoundError: No module named 'semanticui_forms'
ModuleNotFoundError: No module named 'tornado-forms'

Ads