Can someone tell me what's wrong with this code?

jsp
java

(Piumi Wathsala) #1

This doesn’t create any errors but my data is not sent to the database. Please hep.

catering.jsp

<%@ page language=“java” contentType=“text/html; charset=ISO-8859-1”
pageEncoding=“ISO-8859-1”%>

Hotel
<!-- Place favicon.ico and apple-touch-icon.png in the root directory -->
<link rel="shortcut icon" href="favicon.ico">

<link href='https://fonts.googleapis.com/css?family=Playfair+Display:400,700,400italic,700italic|Merriweather:300,400italic,300italic,400,700italic' rel='stylesheet' type='text/css'>

<!-- Animate.css -->
<link rel="stylesheet" href="css/animate.css">
<!-- Icomoon Icon Fonts-->
<link rel="stylesheet" href="css/icomoon.css">
<!-- Simple Line Icons -->
<link rel="stylesheet" href="css/simple-line-icons.css">
<!-- Datetimepicker -->
<link rel="stylesheet" href="css/bootstrap-datetimepicker.min.css">
<!-- Flexslider -->
<link rel="stylesheet" href="css/flexslider.css">
<!-- Bootstrap  -->
<link rel="stylesheet" href="css/bootstrap.css">

<link rel="stylesheet" href="css/style.css">

<link href="css/bootstrap.min.css" rel="stylesheet">

<link href="css/stylish-portfolio.css" rel="stylesheet">
<link href="css/stylish-portfolio.min.css" rel="stylesheet">
<link rel="stylesheet" href="css/demo.css">
<link href="scss/anime.css" rel="stylesheet">
<link rel="stylesheet" href="css/sociel.css">
<link rel="stylesheet" href="css/footer-basic-centered.css">
<link href="css/style.css" rel="stylesheet">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.1.0/css/all.css" integrity="sha384-lKuwvrZot6UHsBSfcMvOkWwlCMgc0TaWr+30HWe3a4ltaBwTZhyTEggF5tJv8tbt" crossorigin="anonymous">

<!-- Modernizr JS -->
<script src="js/modernizr-2.6.2.min.js"></script>
<!-- FOR IE9 below -->
<!--[if lt IE 9]>
<script src="js/respond.min.js"></script>
<![endif]-->
<ul class="nav navbar-nav navbar-left">
    <li><a href="index.html"><i class="fas fa-home"></i></a></li>


    <li><a href="about.html"><b>About</b></a></li>
    <li> <a href="contactUs.html"><b>Contact Us</b> </a></li>
</ul>

<ul  class="nav navbar-nav navbar-right">
    <li id="mylist">
        <button class="btn btn-success btn-lg"><i class="fas fa-user"></i></button>
        <button class="btn btn-danger btn-lg"><i class="fas fa-user-tie"></i></button>
    </li>

</ul>




	<form method="POST" action="Catering">
	<table>

		<tr>
			<td>Date</td>
			<td><input type="date" class="form-control datepicker" placeholder="dd/mm/yyyy" id="cus_date"/></td>
		</tr>
		<tr>
			<td>No.Of People</td>
			<td><select class="form-control selectpicker" id="cus_ppl">
                                <option value="1">Select from list</option>
                                <option value="2">30</option>
                                <option value="3">40</option>
                                <option value="4">50</option>
                                <option value="5">100</option>
                                <option value="6">150</option>
                                <option value="7">200</option>
                            </select></td>
		</tr>
		<tr>
			<td>Venue</td>
			<td><input type="text" class="form-control" placeholder="No.45, Kadawatha, Wattala" id="venue"/></td>
		</tr>
		<tr>
			<td>Contact Person</td>
			<td><input type="text" class="form-control" placeholder="A.M De Alwis" id="cus_name"/></td>
		</tr>
		<tr>
			<td>Phone Number</td>
			<td><input type="text" class="form-control" placeholder="0777456345" id="cus_num"/></td>
		</tr>
		<tr>
			<td>Email Id</td>
			<td><input type="email" class="form-control" placeholder="Info@yourdomain.com" id="cus_email"/></td>
		</tr>
		<tr>	
			<td> <input type="submit" value="book now" class="btn search_toggle" /></td>
		</tr>
	</table>
</form>


<p class="footer-company-motto"><b>Good food | Good Vibes</b></p>

<section id="lab_social_icon_footer">
    <!-- Include Font Awesome style sheet in Header -->
    <link href="//maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css" rel="stylesheet">
    <div class="container">
        <div class="text-center center-block">
            <a href="https://www.facebook.com/"><i id="social-fb" class="fa fa-facebook-square fa-3x social"></i></a>
            <a href="https://twitter.com/"><i id="social-tw" class="fa fa-twitter-square fa-3x social"></i></a>
            <a href="https://plus.google.com/"><i id="social-gp" class="fa fa-google-plus-square fa-3x social"></i></a>
            <a href="mailto:#"><i id="social-em" class="fa fa-envelope-square fa-3x social"></i></a>
        </div>
    </div>
</section>


<p class="footer-company-name"><b>Hotel Sujanee &copy; 2018</b></p>

Catering.java (Servlet)

import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**

  • Servlet implementation class Catering
    */
    @WebServlet("/Catering")
    public class Catering extends HttpServlet {
    private static final long serialVersionUID = 1L;

    /**

    • @see HttpServlet#HttpServlet()
      */
      public Catering() {
      super();
      // TODO Auto-generated constructor stub
      }

    /**

    • @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
      */
      protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
      // TODO Auto-generated method stub
      response.getWriter().append("Served at: ").append(request.getContextPath());
      }

    /**

    • @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
      */
      protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
      try {
      String cus_date = request.getParameter(“cus_date”);
      String cus_ppl = request.getParameter(“cus_ppl”);
      String venue = request.getParameter(“venue”);
      String cus_name = request.getParameter(“cus_name”);
      String cus_num = request.getParameter(“cus_num”);
      String cus_email = request.getParameter(“cus_email”);

       String sql = "insert into cater(cus_date,cus_ppl,venue,cus_name,cus_num,cus_email) values(?,?,?,?,?,?)";
       Class.forName("com.mysql.jdbc.Driver");
       Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/sujanee", "root", "");
       java.sql.PreparedStatement ps = conn.prepareStatement(sql);
       ps.setString(1, cus_date);
       ps.setString(2, cus_ppl);
       ps.setString(3, venue);
       ps.setString(4, cus_name);
       ps.setString(5, cus_num);
       ps.setString(6, cus_email);
      
       
       ps.executeUpdate();
       response.sendRedirect("cateringDisplay.jsp");
       return;
      

      }catch(ClassNotFoundException e) {

       e.printStackTrace();
      

      }catch(SQLException e) {

       e.printStackTrace();
      

      }
      }

}