I've enough knowledge to develop in Java SE/JavaFX (Desktop), but it's my 1st time with Java EE (WEB). I'd like to build a basic app only getting Login and Password in a HTML/JSP, calling a Servlet (in Java) and returning a single message to the HTML/JSP. This time I want to do that the "hard way", without any IDE. So, I've installed Tomcat 7.0 and I have those modules:
Java (this example only receive from HTML/JSP)
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 loginServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String userName = request.getParameter("userName");
String password = request.getParameter("password");
out.println("<html>");
out.println("<body>");
out.println("Hello " + " " + userName + "welcome to my blog");
out.println("Your password is : " + " " + password + "<br>");
out.println("</body></html>");
}
}
HTML/JSP
<!DOCTYPE html>
<html lang ="pt-br">
<head>
<title> loginServlet </title>
<meta http-equiv = ”Content-Type” content=”text/html; charset=UTF-8”>
<link rel="stylesheet" type="text/css"
href="c:/java/html/css/estilo.css"/>
</head>
<body>
<h2> Login Page </h2>
<p>Please enter your username and password</p>
<form method="GET" action="loginServlet">
<p> Username <input type="text" name="userName" size="50"> </p>
<p> Password <input type="text" name="password" size="20"> </p>
<p> <input type="submit" value="Submit" name="B1"> </p>
</form>
</body>
</html>
WEB.XML
<?xml version="1.0" encoding="ISO-8859-1" ?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
<display-name>loginServlet</display-name>
<description>
This is a simple web application with a source code organization
based on the recommendations of the Application Developer's Guide.
</description>
<servlet>
<servlet-name>loginServlet</servlet-name>
<servlet-class>java.loginServlet.WebContaint.WEB-
INF.classes.loginServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>loginServlet</servlet-name>
<url-pattern>/loginServlet</url-pattern>
</servlet-mapping>
</web-app>
Paths and folders
loginServlet.class
is inC://java/loginServlet/WebContaint/WEB-INF/classes/
loginServlet.jsp
is inC://java/loginServlet/WebContaint/
web.xml
is inC://java/loginServlet/WebContaint/WEB-INF/
loginServlet.war
is inC:\Program Files\Apache Software Foundation\ Tomcat 7.0\webapps
When I try to call in my Chrome, using a localhost (http://localhost:8080/loginServlet), I receive a 404 Error.