Hi all,
Today i downloaded Eclipse
IDE and tried to do my first program.I created an HTML file and an
servlet class.The HTML file will accept emp details and the servlet program will just Echo those details.When i run HTML file i am getting
description: The requested resource (/JavaWebProject/servlet/EmpEchoServlet) is not available.
Below is the code.
//EmpEcho.html
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Echo emp details</title>
</head>
<body bgcolor=cyan text=blue>
<h2>Enter emp details</h2>
<form name=EMPFORM method=GET action='servlet/EmpEchoServlet'>
Enter Employee Number
<input type=text name=EMPNO size=15>
<br><br>
Enter Employee Name
<input type=text name=ENAME size=25>
<br><br>
Enter Employee Job
<input type=text name=JOB size=15>
<br><br>
<input type=Submit value='Send Data'>
</form>
</body>
</html>
//EmpEchoServlet.java
package com.test;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class for Servlet: EmpEchoServlet
*
*/
public class EmpEchoServlet extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet {
static final long serialVersionUID = 1L;
/* (non-Java-doc)
* @see javax.servlet.http.HttpServlet#HttpServlet()
*/
public EmpEchoServlet() {
super();
}
/* (non-Java-doc)
* @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html><body>");
out.println("<h2 align=center>Received details");
out.println("<h3> Employee Details </h3>");
//Receive data from web browser
String p1= request.getParameter("EMPNO");
String p2= request.getParameter("ENAME");
String p3= request.getParameter("JOB");
// send the parameter to the web browser
out.println("<br><br>EMPLOYEE NUMBER:"+ p1);
out.println("<br><br>EMPLOYEE NAME:"+p2);
out.println("<br><br>EMPLOYEE JOB:"+p3);
out.println("</body></html>");
}
/* (non-Java-doc)
* @see javax.servlet.http.HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*///protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
}
//web.xml
<servlet>
<display name>EmpEchoServlet
<servlet name>EmpEchoServlet
<servlet class>com.test.EmpEchoServlet
</servlet>
<servlet mapping>
<servlet name>EmpEchoServlet
<url-pattern>/EmpEchoServlet
</servlet mapping>
Please tell me what i am doing wrong.