import java.io.*;
import java.io.IOException;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.WebServlet;
/**
*
Servlet implementation class A
*/
@WebServlet("/A")
public class A extends HttpServlet {
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
public void init()throws ServletException{
System.out.println(getServletConfig());
String s=getInitParameter("Name");
String s1=getInitParameter("Password");
System.out.println("Name"+s);
System.out.println("Password"+s1);
ServletConfig config=getServletConfig();
System.out.println(config);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
ServletConfig config=getServletConfig();
String s=config.getInitParameter("Name");
String s1=config.getInitParameter("Password");
response.setContentType("text/html");
PrintWriter out=response.getWriter();
out.println("Your Name is:"+s);
out.println("Your Password is:"+s1);
}
}
there ia also a HTML page containg a submit button,when i run this program in eclipse mars....the html page is displayed,but when i click submit button it does not redirect to servlet page.after reruning the project error-get method is not supported.
htmlpage.
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body><center>
<form action="A" method="post">
<input type="button" value="submit">
</form>
</center>
</body>
</html>
web.xml.
<?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_3_0.xsd" version="3.0">
<display-name>Demo</display-name>
<servlet>
<servlet-name>A</servlet-name>
<servlet-class>A</servlet-class>
<init-param>
<param-name>Name</param-name>
<param-value>Mithun Sarkar</param-value>
</init-param>
<init-param>
<param-name>Password</param-name>
<param-value>1234r</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>A</servlet-name>
<url-pattern>"/A"</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>Welcome.html</welcome-file>
</welcome-file-list>
</web-app>
I am using apache v-8. but using apache facing problem,default port is 8080,i chnged it to 80 after seeing that 80 is open.jdk-1.8,OS-windows 7.