fname.html
<html><head><title>My Home Page</title></head>
<body>
<form method="get" action="fnameservlet">
<b>Enter Your Name: </b> <input type="text" name="fname"><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
prj2servlet.java
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class prj2servlet extends HttpServlet
{
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out=response.getWriter();
String s1 = request.getParameter("fname");
out.println("WELCOME " + s1);
}
}
Web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0">
<servlet>
<servlet-name>prj2servlet</servlet-name>
<servlet-class>prj2servlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>prj2servlet</servlet-name>
<url-pattern>/fnameservlet</url-pattern>
</servlet-mapping>
</web-app>
No comments:
Post a Comment