import javax.servlet.http.*;
import java.io.*;
public class DataServ extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
res.setContentType("text/html");
PrintWriter pw = res.getWriter();
String name = req.getParameter("persdata_eurn");
String cname = req.getParameter("persdata_eurc");
pw.println("<center><h3>HELLO..! Mr/Mrs. " + name + "</h3></center>");
pw.println("<center><h3>Your COURSE is " + cname + "</h3></center>");
}
public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
doGet(req, res);
}
web.xml:
<web-app>
<servlet>
<servlet-name>abc</servlet-name>
<servlet-class>DataServ</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>abc</servlet-name>
<url-pattern>/getdata</url-pattern>
</servlet-mapping>
</web-app>
NOTE:
1. Whenever we are not entering the data in html form that data will be treated as empty space.
2. Query string represents the data which is passed by client to the servlet through html form. URI stands for Uniform Resource Indicator which gives the location of servlet where it is available. URL stands for Uniform Resource Locator which gives at which port number, in which server a particular JSP or servlet is running. ht represents a context path which can be either a document root or a war file.
|
No comments:
Post a Comment