0

I have this error when i started loginPage.jsp form and type a username and password :

type Status report

message /WHFM/LoginServlet.java

description The requested resource is not available.

What am i missing? I read article about same problem, but I think case sensitive is right, here.

 <form name="loginForm" method="Post" action="LoginServlet.java">
    <table>
    <tr>
    <td>Username:</td>
    <td><input type="text" name="uname"></td></tr>


    <tr><td>Password:</td>
    <td><input type="password" name="pass"></td>
    </tr>
    <tr><td></td><td><input type="submit" value="submit" name="submit"></td></tr>
    </table>

    </form>

and servlet is :

 protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    DBConnection connString = new DBConnection();
    String query = "";
    String username= request.getParameter("uname");
    String password = request.getParameter("pass");
    int counter= 0;

    try {
         response.setContentType("text/html");
            PrintWriter out=response.getWriter();
        connString.getConnection();
        query="Select * from user where username='"+username+"' and password='"+password+"' ";
        System.out.println(query);
        Statement st = connString.getConnection().createStatement();
        ResultSet rs= st.executeQuery(query);
        while(rs.next()){
            counter++;
        }
        if(counter>0){
            response.sendRedirect("welcome.jsp");
        }
        else{
            response.sendRedirect("LoginPage.jsp");
        }

this is my XML:

  <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 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">
  <display-name>WHFM</display-name>
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
     </welcome-file-list>


<servlet>

<servlet-name>LoginServlet</servlet-name>
<servlet-class>servlets.LoginServlet</servlet-class>
</servlet>

<servlet-mapping>

<servlet-name>LoginServlet</servlet-name>
<url-pattern>/LoginServletPath</url-pattern>
</servlet-mapping>
</web-app>
KeySi
  • 61
  • 2
  • 3
  • 9

2 Answers2

1

The <form action> URL must not point to the class file name of the servlet class. It must point to an URL which is publicly accessible by a webbrowser, exactly the one as you'd need to enter in browser's address bar.

You have mapped the servlet on an URL pattern of /LoginServletPath, so it is available by http://localhost:8080/WHFM/LoginServletPath, so you need to fix your <form action> URL accordingly:

<form action="LoginServletPath">

or, if you prefer to be able to move your JSP file around everywhere without worrying about relative URLs,

<form action="${pageContext.request.contextPath}/LoginServletPath">

Unrelated to the concrete problem, your JDBC code is leaking resources. I'd fix that as soon as possible.

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
0

make sure that you located all classes in webapp folder and mapping your 'servlet' and a 'servlet-mapping' are in your web.xml

like :

<servlet>

<servlet-name>HelloWorld</servlet-name>
<servlet-class>your.package.name.HelloWorld</servlet-class>

</servlet>

<servlet-mapping>

<servlet-name>HelloWorld</servlet-name>
<url-pattern>/hello</url-pattern>

</servlet-mapping>

this article may help : Invoker Servlet

Community
  • 1
  • 1
Mohammed Sayed
  • 135
  • 1
  • 7