Reputation: 1102
I have written this code for servlet
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class Httpservlet1 extends HttpServlet
{
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException
{
String color = request.getParameter("color");
response.setContentType("text/html");
PrintWriter pw = response.getWriter();
pw.println("<B>The selected color is: ");
pw.println(color);
pw.close();
}
}
i have compiled it and its corresponding html file action attribute value is
action="http://localhost:8765/HS/HTTPSERVLET">
and web.xml contains
servlet-name four
servlet-class Httpservlet1
servlet-name four
url-pattern /HTTPSERVLET in xml code format still its showing error message on running it
Upvotes: 1
Views: 488
Reputation: 7625
Perhaps your web.xml is not properly formed. It works OK for me.
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<servlet>
<servlet-name>four</servlet-name>
<servlet-class>Httpservlet1</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>four</servlet-name>
<url-pattern>/HTTPSERVLET</url-pattern>
</servlet-mapping>
</web-app>
Upvotes: 2