servlet does not envoke when I call a from method.

Posted by saloni on Stack Overflow See other posts from Stack Overflow or by saloni
Published on 2010-04-06T06:53:02Z Indexed on 2010/04/06 11:53 UTC
Read the original article Hit count: 344

Filed under:
|
|

My web.xml is like

    <web-app version="2.4"
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">
    <display-name>sample</display-name>
    <servlet>
        <servlet-name>Sampleclass</servlet-name>
        <servlet-class>sample.SampleClass</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>Sampleclass</servlet-name>
        <url-pattern>/SampleClass</url-pattern>
    </servlet-mapping>
    <welcome-file-list>
        <welcome-file>/page/form.jsp</welcome-file>
    </welcome-file-list>
</web-app>

and form.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
    <h1>A simple web application</h1>
        <form method="POST" name="Sampleclass" action="SampleClass">
            <label for="name">Enter your name </label>
            <input type="text" id="name" name="name"/><br><br>
            <input type="submit" value="Submit Form"/>
            <input type="reset" value="Reset Form"/>
        </form>
</body>
</html>

and SampleClass.java is

public class SampleClass extends HttpServlet {
    public void init(ServletConfig config) throws ServletException {
        super.init(config);
        }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) 
                throws ServletException, IOException {
        String name = request.getParameter("name");
        String age = request.getParameter("age");
        PrintWriter out = response.getWriter();
        out.write("<html>Hello Your name is "+name +", and your age is "+age+"</html>");
    }
    public void destroy() {

    }


}

but I am getting error when I entered to submit button of form.jsp
and error is

type Status report

message HTTP method POST is not supported by this URL

description The specified HTTP method is not allowed for the requested resource (HTTP method POST is not supported by this URL).

I am not understanding that what is the problem exactly ? Please help..

© Stack Overflow or respective owner

Related posts about servlets

Related posts about java