index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Servlet Request</title>
<form method="get" action="check">
Enter your name<input type="text" name="name"> <br>
<input type="submit" value="login">
</form>
</head>
<body>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Servlet Request</title>
<form method="get" action="check">
Enter your name<input type="text" name="name"> <br>
<input type="submit" value="login">
</form>
</head>
<body>
</body>
</html>
</html>
Servlet Program:
//DemoReq1.java
import javax.servlet.http.*;
import javax.servlet.*;
import java.io.*;
public class DemoReq1 extends HttpServlet
{
public void doGet(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException
{
res.setContentType("text/html");
PrintWriter pw=res.getWriter();
String name=req.getParameter("name");//will return value
pw.println("Namasthe "+name);
pw.close();
}
}
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app>
<servlet>
<servlet-name>Raj</servlet-name>
<servlet-class>DemoReq1</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Raj</servlet-name>
<url-pattern>/check</url-pattern>
</servlet-mapping>
</web-app>
rereree
You may like the following posts:
No comments:
Post a Comment