Good afternoon,
I just configured tomcat and used java servlet pages. I am new to this and could not get to the index page successfully, but if I directly tried to click on the form action and pass a certain parameter, I could see the results. Please guide me if I missed something.
JSP code
<div align="center" style="margin-top: 50px;"> <form action="CrunchifyServlet"> 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> Please enter your Age: <input type="text" name="age" size="20px"> <br><br> <input type="submit" value="submit"> </form> </div>
Java code
public class HelloCrunchify 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"); String age = request.getParameter("age"); 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> Crunchify.com JSP Servlet Example </title> \n" + "</head> \n" + "<body> <div align='center'> \n" + "<style= \"font-size=\"12px\" color='black'\"" + "\">" + "Username: " + username + " <br> " + "Password: " + password + " <br> " + "Age: " + age + "</font></body> \n" + "</html>" ); }
}
web.xml
<display-name>CrunchifyJSPServletExample</display-name> <welcome-file-list> <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>com.crunchify.jsp.servlet.HelloCrunchify</servlet-class> </servlet> <servlet-mapping> <servlet-name>Hello</servlet-name> <url-pattern>/CrunchifyServlet</url-pattern> </servlet-mapping> </web-app>

and if I tried to click this localhost:9080/CrunchifyJSPServletExample/Crunchify.jsp , I get an HTTP status of 404.
Help will be appreciated.
thanks
source share