0

I am having trouble after I hit submit on my login.jsp. I receive an error message stating:

HTTP Status 404 - /LA/Controller

type Status report

message /LA/Controller

description The requested resource is not available.

Apache Tomcat/7.0.50

  • I am using Eclipse Java EE and tomcat server. Any help/suggestions would be greatly appreciated. Thanks in advance!

Cheers

My directory is as follows in eclipse Java EE:

LA
  - Java Resources
  - src
  - p1
    - Controller.java
WebContent
 - META-INF
 -VIEWS
     - .....
     - login.jsp
     - index.jsp
     - welcome.jsp
- WEB-INF
      -lib
          jstl-1.2.jar
          mysql-connector-java...
      -web.xml

My servlet- Controller.java:

package p1;


public class Controller extends HttpServlet {
private static final long serialVersionUID = 1L;
//  static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";  
//  static final String DB_URL = "jdbc:mysql://localhost/jdb";  

/**
 * @see HttpServlet#HttpServlet()
 */
public Controller() {

    super();
    // TODO Auto-generated constructor stub
}

///=============== 
 public static boolean validate(String name, String pass) {          
    boolean status = false;  
    Connection conn = null;  
    PreparedStatement pst = null;  
    ResultSet rs = null;  

    String url = "jdbc:mysql://localhost:3306/";  
    String dbName = "jdb";  
    String driver = "com.mysql.jdbc.Driver";  
    String userName = "root";  
    String password = "bluepanda1";  
    try {  
        Class.forName(driver).newInstance();  
        conn = DriverManager  
                .getConnection(url + dbName, userName, password);  

        pst = conn  
                .prepareStatement("select * from login where user=? and password=?");  
        pst.setString(1, name);  
        pst.setString(2, pass);  

        rs = pst.executeQuery();  
        status = rs.next();  

    } catch (Exception e) {  
        System.out.println(e);  
    } finally {  
        if (conn != null) {  
            try {  
                conn.close();  
            } catch (SQLException e) {  
                e.printStackTrace();  
            }  
        }  
        if (pst != null) {  
            try {  
                pst.close();  
            } catch (SQLException e) {  
                e.printStackTrace();  
            }  
        }  
        if (rs != null) {  
            try {  
                rs.close();  
            } catch (SQLException e) {  
                e.printStackTrace();  
            }  
        }  
    }  
    return status;  
}  


/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws              

   ServletException, IOException {
// TODO Auto-generated method stub
    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    out.print("Test");

   }
/**
 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
 */
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws   
   ServletException, IOException {
    // TODO Auto-generated method stub
    response.setContentType("text/html");
    PrintWriter out = response.getWriter();

    String n=request.getParameter("username");
    String p=request.getParameter("password");

    HttpSession session = request.getSession(false);
    if(session!=null)
        session.setAttribute("name",n);

    if(Controller.validate(n, p)){
        RequestDispatcher rd = request.getRequestDispatcher("welcome.jsp");
        rd.forward(request, response);
    }
    else{
        out.print("<p style=\"color:red\"> Sorry username or password             
       error</p>");
        RequestDispatcher rd = request.getRequestDispatcher("login.jsp");
        rd.include(request, response);
    }
    out.close();    
}

 }

my login.jsp:

<%@ page language="java" contentType="text/html; charset=US-ASCII"
pageEncoding="US-ASCII"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"      
"http://www.w3.org/TR/html4/loose.dtd">
 <html>
 <head>  
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<meta name="keywords" content="" />
<meta name="description" content="" />
<link href="http://fonts.googleapis.com/css?family=Open+Sans:400,300,600,700,800"     
rel="stylesheet" />
<link href="default.css" rel="stylesheet" type="text/css" media="all" />
<link href="fonts.css" rel="stylesheet" type="text/css" media="all" />
<c:url var="actionUrl" value="/Controller"/> 



</head>
<body>
<div id="header-wrapper">
<div id="header" class="container">
    <div id="logo">
        <h1><a href="#">The Legal Network</a></h1>
    </div>
    <div id="menu">
        <ul>
            <li><a href="index.jsp"  accesskey="1" title="">Homepage</a></li>
            <li><a href="createAct.jsp" accesskey="2" title="">Create   
   Account</a></li>
            <li><a href="login.jsp" accesskey="3" title="">Login</a></li>
            <li><a href="logout.jsp" accesskey="4" title="">Logout</a></li>
            <li><a href="contact.jsp" accesskey="5" title="">Contact Us</a>   
  </li>
        </ul>
    </div>
</div>
  </div>
  <div id="featured">&nbsp;</div>
<div id="wrapper">
<div id="page" class="container">
    <div id="content">
        <div class="title">
            <h2>Log In</h2>
            <form action="Controller" method="post">
            <table>
            <tr>
                <td>Username:</td>
                <td><input type="text" name="Username"></td> 
            </tr>
            <tr>
                <td>Password:</td>
                <td><input type="password" name="Password"></td> 
            </tr>
            <tr>
                <td><input type="submit" name="submit"></td> 
            </tr>
            </table>
            </form>
            </div>

    </div>
</div>
  </div>
  </body>
  </html>

My web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    
 xmlns="http://java.sun.com/xml/ns/javaee"    
 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web- 
 app_3_0.xsd" id="WebApp_ID" version="3.0">
<servlet>  
    <servlet-name>Controller</servlet-name>  
    <servlet-class>p1.Controller</servlet-class>  
</servlet>  

<servlet-mapping>   
    <servlet-name>Controller</servlet-name>  
    <url-pattern>Controller</url-pattern>  
</servlet-mapping>  

<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
<welcome-file>login.jsp</welcome-file>
<welcome-file>welcome.jsp</welcome-file>
</welcome-file-list>
</web-app>

1 Answers1

0

As per the comments, once you moved all the jsp files out of VIEWS folder, it did work! becoz of the below mentioned, request.getRequestDispatcher("welcome.jsp");

you could have mentioned VIEWS folder details also while dispatch the request.

Vijay Kumar
  • 9
  • 1
  • 4
  • This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post - you can always comment on your own posts, and once you have sufficient [reputation](http://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](http://stackoverflow.com/help/privileges/comment). – blalasaadri Oct 07 '14 at 10:59
  • oh, really! thank you. Its not critic sir, think normally if possible. – Vijay Kumar Oct 08 '14 at 09:56