Search code examples
javawebspherefile-not-found

Websphere file not found error


I'm a beginner in Java. I have developed a jsp page that accepts the username and password and then a java page is executed that validates against a hardcoded value. The issue is that it runs fine on Tomcat. The webpage displays the message from the java page. But the same thing does not work on IBM webshpere. When I click on submit button, I get a file not found error. Please help.

Here's the JSP content:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!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=ISO-8859-1">
<title>Login Example</title>
</head>
<body>
<form name="loginform" action="login" method="post">
<p>Enter User Name: <input type="text" name="getusername"><br>
Enter Password: <input name="getpassword" type="password"><br>
<input type="submit">
</form>

</body>
</html>

================

Here's the Java file content

package test.ae;


import java.io.IOException;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
/**
 * Servlet implementation class Login
 */
@WebServlet(description = "Login Servlet", urlPatterns = { "/login" })
public class Login extends HttpServlet {
    private static final long serialVersionUID = 1L;

    public Login()
    {
        super();
    }
    public void init(ServletConfig config) throws ServletException {}

    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("Service method of the servlet");
        String username = "user";
        String password = "root";

        String un= request.getParameter("getusername");
        String pw= request.getParameter("getpassword");
        String msg = "";

        if(un.equals(username) && pw.equals(password))
        {
            msg = "Hello " + un;
        }
        else
        {
            msg = "Login failure";
        }

        response.setContentType("text/html");
        PrintWriter out = response.getWriter();
        out.println("<font size='6' color=red>" + msg + "</font>");
    }

}

======================


Solution

  • What version of WebSphere server are you using? Does it support @WebServlet annotation (Java Servlet 3.0 (JSR 315), which is part of Java EE 6)

    You may use url-pattern in web.xml instead: http://docs.oracle.com/cd/E13222_01/wls/docs81/webapp/web_xml.html