0
package mypackage;


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

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

public class Register extends HttpServlet {


    static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
    static final String DB_URL = "jdbc:mysql://localhost:3306/test";
    static final String USER = "root";
    static final String PASS = "";
    Connection conn = null;
    Statement stmt = null;
    public void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {


        response.setContentType("text/html");
        PrintWriter out = response.getWriter();

        String n=request.getParameter("userName");
        String p=request.getParameter("userPass");
        String e=request.getParameter("userEmail");
        String c=request.getParameter("userCountry");

        try {
            Class.forName("com.mysql.jdbc.Driver");
        conn = DriverManager.getConnection(DB_URL, USER, PASS);

        stmt=conn.createStatement();
        String sql="insert into test values(?,?,?,?)";


        } catch (ClassNotFoundException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } catch (SQLException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }



    }
}

This is my code I have created index.html file when i and in web.xml i have write code like this ..

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
  <servlet>
    <servlet-name>RegisterServlet</servlet-name>
    <servlet-class>mypackage.Register</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>RegisterServlet</servlet-name>
    <url-pattern>/Register</url-pattern>
  </servlet-mapping>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
  </welcome-file-list>
</web-app>

But i am Unable to Load html file when i run the application please tell me how to set servlet-name,servlet-classes an all in web.xml file . please help am new in Jsp servlet .

user2794306
  • 175
  • 3
  • 5
  • 24
  • Your servlet mapping is fine, can you show the error you are getting? – Prasad Kharkar Sep 20 '13 at 08:47
  • whats your error??..are you unable to load index.html page??...Is it within web or have you kept it in web-inf?..If its within web-inf your application cannot access it... – ntstha Sep 20 '13 at 08:49
  • HTTP Status 404 - /Registration/ – user2794306 Sep 20 '13 at 08:52
  • Mapping looks OK. What URL are you trying to load? Have you considered the server's port? Is there anything suspicious in server's log? – Kojotak Sep 20 '13 at 08:53
  • http://localhost:8080/Registration/ coming But page is not loading – user2794306 Sep 20 '13 at 08:57
  • It should be localhost:8080/Register – Kojotak Sep 20 '13 at 09:00
  • No not working still page is not laoding how to set Servlet name what servlet name can u please tell me? – user2794306 Sep 20 '13 at 09:06
  • Servlet-name (in web.xml) is used for pairing servlet declaration (implementation class) with URL patterns, which is RegisterServlet in your case (=you have already set the name). Have you checked the server logs? What servlet container are you using and how are you deploying your app? – Kojotak Sep 20 '13 at 09:15
  • Is this question from you ? http://stackoverflow.com/questions/18913395/how-registration-page-in-servlet . It looks like a duplicate, if then please remove it. – A4L Sep 20 '13 at 09:41

1 Answers1

0

As per your web.xml

your index.html should be directly inside your project folder

structure should be like this

project/index.html

and your servlet class should be in inside class folder

project/WEB-INF/classes/servlet.class
SpringLearner
  • 13,738
  • 20
  • 78
  • 116