I am using Java Servlet in NetBeans. Upon running the code. My BUILD is SUCCESSFULL, and my index.jsp is loading successfully. But I get a Error 505, after redirecting. Please help me out with this. This is the first time I am using Java Servlets.
Most of the code is autocomplete by NetBeans, Here I just want something to be printed in the console. But I see no reason to get a Error 505. Please help!
index.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Student Details</title>
</head>
<body>
<h1>Student Details</h1>
<form action="details">
<label>Enter Student ID: </label>
<input name="id" type="text">
<br>
<label>Enter Student Name: </label>
<input name="name" type="text">
<br>
<input type="submit">
</form>
</body>
</html>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
<servlet>
<servlet-name>getStudentDetails</servlet-name>
<servlet-class>com.mycompany.studentdetails.StudentServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>getStudentDetails</servlet-name>
<url-pattern>/details</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
</web-app>
StudentServlet.java
public class StudentServlet extends HttpServlet {
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
try ( PrintWriter out = response.getWriter()) {
/* TODO output your page here. You may use following sample code. */
out.println("<!DOCTYPE html>");
out.println("<html>");
out.println("<head>");
out.println("<title>Servlet StudentServlet</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>Servlet StudentServlet at " + request.getContextPath() + "</h1>");
out.println("</body>");
out.println("</html>");
String id = request.getParameter("id");
String name = request.getParameter("name");
System.out.println("Working");
System.out.println(id+name);
}
}
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
@Override
public String getServletInfo() {
return "Short description";
}// </editor-fold>
}