Results 1 to 4 of 4
  1. #1
    Nethra is offline Member
    Join Date
    Nov 2011
    Posts
    2
    Rep Power
    0

    Default Tomcat servlet -Http 404 resource notfound

    I am posting my program for connecting a database from servlet that can be viewed from html page.
    kforce.html
    <html>
    <head>
    <body>
    <h1> K-Force Employment details </h1>
    <form method="post" action="Registration">
    ApplicantId: <input type="text" name="id"/><br/></br>
    FirstName: <input type="text" name="fname"/><br/></br>
    MiddleName: <input type="text" name="mname"/><br/></br>
    lastName: <input type="text" name="lname"/><br/></br>
    StreetAddress: <input type="text" name="add"/><br/></br>
    City: <input type="text" name="city"/><br/></br>
    State: <input type="text" name="state"/><br/></br>
    ZipCode: <input type="text" name="zip"/><br/></br>
    HomePhone: <input type="text" name="ph1"/><br/></br>
    WorkPhone: <input type="text" name="ph2"/><br/></br>
    Created Date: <input type="text" name="cdate"/><br/></br>
    Created by: <input type="text" name="cby"/><br/>

    <input type="submit" value="Submit" name="B1"/>
    </form>
    </body>
    </head>
    </html>

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

    public class Registration extends HttpServlet{
    public void init(ServletConfig config) throws ServletException{
    super.init(config);
    }
    public void doPost(HttpServletRequest req, HttpServletResponse res)
    throws ServletException, IOException{
    Connection connection=null;


    // Informs the driver to use server a side-cursor,
    // which permits more than one active statement
    // on a connection.
    String selectMethod = "cursor";

    // Constructor


    ResultSet rs;
    res.setContentType("text/html");
    PrintWriter out = res.getWriter();
    String uId = req.getParameter("id");
    String fname1 = req.getParameter("fname");
    String mname1=req.getParameter("mname");
    String lname1 = req.getParameter("lname");
    String stadd = req.getParameter("add");
    String city1=req.getParameter("city");
    String state1 = req.getParameter("state");
    String zip1 = req.getParameter("zip");
    String hph = req.getParameter("ph1");
    String wph = req.getParameter("ph2");
    String cd = req.getParameter("cd");
    String created = req.getParameter("cby");

    String getConnectionUrl= "jdbc:microsoft:sqlserver://localhost:1433;databaseName=PersonalInformation;se lectMethod=cursor;";

    try{
    Class.forName("com.mysql.jdbc.Driver");
    connection = DriverManager.getConnection(getConnectionUrl, userName, password);
    String sql = "insert into dbo.PersonalInformation() values (?,?,?,?,?,?,?,?,?,?,?)";
    PreparedStatement pst = connection.prepareStatement(sql);
    // CallableStatement cstmt = dbConn.prepareCall(
    //"{call insertTheForm(?, ?, ?, ?)}");
    pst.setString(1, uId);
    pst.setString(2, fname1);
    pst.setString(2, mname1);
    pst.setString(3, lname1);
    pst.setString(4, stadd);
    pst.setString(5, city1);
    pst.setString(6, state1);
    pst.setString(7, zip1);
    pst.setString(8, hph);
    pst.setString(9, wph);
    pst.setString(10, cd);
    pst.setString(11, created);
    int numRowsChanged = pst.executeUpdate();
    out.println("Hello:");
    out.println("'"+fname1+"'");
    pst.close();
    }
    catch(Exception e){
    out.println(e);
    }
    }
    }
    web.xml<?xml version="1.0" encoding="UTF-8" ?>
    <web-app xmlns=”http://java.sun.com/xml/ns/j2ee”
    xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”
    xsi:schemaLocation=”Java 2 Platform, Enterprise Edition (J2EE) : XML Schemas for J2EE Deployment Descriptors
    http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd”

    version=”2.4”>
    <servlet>
    <servlet-name>Register</servlet-name>
    <servlet-class>Registration</servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name>Register</servlet-name>
    <url-pattern>/Registration</url-pattern>
    </servlet-mapping>
    </web-app>

    I sucessfully compiled registration.class.but when I execute http:localhost:8080/kf/kforce.html.iIt throws http 404 error.Please help me and advise me which part goes wrong

    Appreciate your reply!

  2. #2
    dgsdin is offline Member
    Join Date
    Dec 2011
    Posts
    2
    Rep Power
    0

    Default Re: Tomcat servlet -Http 404 resource notfound

    As mentionel in url, Have you created context entry for "kf" in server.xml file

  3. #3
    Nethra is offline Member
    Join Date
    Nov 2011
    Posts
    2
    Rep Power
    0

    Default Re: Tomcat servlet -Http 404 resource notfound

    Can you please explain how to edit web.xml with example.Whether I need to configure the tomcat?.Please advise

  4. #4
    dgsdin is offline Member
    Join Date
    Dec 2011
    Posts
    2
    Rep Power
    0

    Default Re: Tomcat servlet -Http 404 resource notfound

    Quote Originally Posted by Nethra View Post
    Can you please explain how to edit web.xml with example.Whether I need to configure the tomcat?.Please advise
    ok let me try
    first create a context at the end of file in server.xml file as follows
    <Context path="/kf" docBase="kf" debug="0" reloadable="true"/>
    save and close file.
    Your web.xml file seems correct. Restart server. In your post you omitted '//' after 'http:' ensure it is there. Hope this helps

Similar Threads

  1. Replies: 1
    Last Post: 03-27-2012, 04:52 AM
  2. Replies: 3
    Last Post: 06-23-2011, 10:31 PM
  3. HTTP Status 404-The requested resource is not available.
    By DeViLHuNTeR in forum Java Servlet
    Replies: 17
    Last Post: 03-11-2011, 03:40 PM
  4. Replies: 1
    Last Post: 12-02-2008, 01:23 AM
  5. tomcat resource bundle tab not appearing??
    By freddieMaize in forum NetBeans
    Replies: 2
    Last Post: 05-25-2008, 10:15 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •