-1

My index looks like this:

<HTML>
<head>
<title> JSP Servlet Example</title>
</head>
<body>

<div align="center" style="margin-top: 50px;">

    <form action="ServletManager">
        Please enter your Username:  <input type="text" name="username" size="20px"> <br>
        Please enter your Password:  <input type="text" name="password" size="20px"> <br><br>
        <input type="submit" value="submit">
    </form>

</div>

</body>
</HTML>

My servlet:

package helloweb;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.PrintWriter;



public class ServletManager extends HttpServlet {protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            // reading the user input
    String username = request.getParameter("username");
    String password = request.getParameter("password");
    PrintWriter out = response.getWriter();
    out.println (
        "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" +" +
        "http://www.w3.org/TR/html4/loose.dtd\">\n" +
        "<html> \n" +
        "<head> \n" +
        "<meta http-equiv=\"Content-Type\" content=\"text/html; " +
        "charset=ISO-8859-1\"> \n" +
        "<title> JSP Servlet Example  </title> \n" +
        "</head> \n" +
        "<body> <div align='center'> \n" +
            "<style= \"font-size=\"12px\" color='black'\"" + "\">" +
            "Username: " + username + " <br> " +
            "Password: " + password +
            "</font></body> \n" +
        "</html>"
            );
        }
    }

My XML: http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0"> JSPServletExample

    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>

</welcome-file-list>
<servlet>

    <servlet-name>Hello</servlet-name>
    <servlet-class>helloweb.ServletManager</servlet-class>

</servlet>
<servlet-mapping>

    <servlet-name>Hello</servlet-name>
    <url-pattern>/ServletManager.java</url-pattern>

</servlet-mapping>

Here is my issue:

Firefox can’t find the file at /C:/Users/HP/IdeaProjects/ourdemo /web/ServletManager?username=hello&password=hello.`

I host at the tomcat 7 server.

The first page appears. I type in the username and password, and I get this. Please help.

Shanky301
  • 52
  • 7
  • Please note that this approach is entirely obsolete; unless this is for a class that has not been updated in 20 years, you should use a Web framework like Spring MVC that handles most of this for you (and in that case, you should also use Spring Security to handle the security pieces like user login). – chrylis -cautiouslyoptimistic- Feb 16 '20 at 05:32
  • First open the JSP by http:// URL and not by a file:// URL. Then fix your form action and servlet mapping conform the instructions in the abovelinked duplicate. – BalusC Feb 16 '20 at 11:09

1 Answers1

0

Please change the url pattern change this in web.xml from /ServletManager.java to /ServletManager and try https://javabelazy.blogspot.com/2010/02/student-registration-form-in-java.html (Working code)

Konzern
  • 110
  • 10