HTTP Status 404 – The requested resource is not available –

I’ve come to across this issue and spent some time searching here for similar problems, but most cases are related to upper/lower-case mistakes.
The thing is, on my computer at home it works just fine, but now that I’ve imported it on my laptop it just wont function right.

I get HTTP Status 404 – /Web/RegisterServlet.do when I try to run a servlet from my jsp file.

My Jsp:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<title>Dynamic Example</title>
</head>
<body>
    <form action="RegisterServlet.do" method="post">

        <table>
            <tr>
                <td align="right">Username:</td>
                <td align="left"><input type="text" name="username" /></td>
            </tr>
            <tr>
                <td align="right">Real name:</td>
                <td align="left"><input type="text" name="realname" /></td>
            </tr>
            <tr>
                <td align="right">Password:</td>
                <td align="left"><input type="text" name="password1" /></td>
            </tr>
            <tr>
                <td align="right">Password (again):</td>
                <td align="left"><input type="text" name="password2" /></td>
            </tr>
            <tr>
                <td align="right">Email:</td>
                <td align="left"><input type="text" name="email1" /></td>
            </tr>
            <tr>
                <td align="right">Email (again):</td>
                <td align="left"><input type="text" name="email2" /></td>
            </tr>

            <tr>
                <td align="right">Address</td>
                <td align="left"><input type="text" name="address" /></td>
            </tr>
            <tr>
                <td align="right">Country:</td>
                <td align="left"><input type="text" name="country" /></td>
            </tr>
            <tr>
                <td align="right"><input type="submit" value="Register" /></td>
            </tr>

        </table>

    </form>
</body>
</html>

My servlet:

package web;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;

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

public class RegisterServlet extends HttpServlet {

    protected void doPost(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        boolean good = true;
        String username = req.getParameter("username");
        String realname = req.getParameter("realname");
        String password1 = req.getParameter("password1");
        String password2 = req.getParameter("password2");
        String email1 = req.getParameter("email1");
        String email2 = req.getParameter("email2");
        String address = req.getParameter("address");
        String country = req.getParameter("country");

        if (username == "" || realname == "" || password1 == ""
                || password2 == "" || email1 == "" || email2 == ""
                || address == "" || country == "") {
            good = false;
        }

        if (!password1.equals(password2)) {
            good = false;
        }

        if (!email1.equals(email2)) {
            good = false;
        }

        if (good == false) {
            resp.sendRedirect("Register.jsp");
        } else {

            FileWriter fw = new FileWriter("users.txt", true);

            PrintWriter pw = new PrintWriter(fw);
            pw.println("[" + username + "][" + realname + "][" + password1
                    + "][" + email1 + "][" + address + "][" + country + "]");
            pw.close();

            req.getRequestDispatcher("Login.jsp").forward(req, resp);
        }

    }
}

My 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"
    version="3.0">
    <servlet>
        <servlet-name>Dynamic Example Servlet</servlet-name>
        <servlet-class>web.LoginServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>Dynamic Example Servlet</servlet-name>
        <url-pattern>/LoginServlet.do</url-pattern>
    </servlet-mapping>
    <servlet>
        <servlet-name>Dynamic Example Servlets</servlet-name>
        <servlet-class>web.RegisterServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>Dynamic Example Servlets</servlet-name>
        <url-pattern>/RegisterServlet.do</url-pattern>
    </servlet-mapping>
</web-app>

My file setup:
http://i.stack.imgur.com/U3Qg5.png


Source: jsp

Leave a Reply