❮ Previous Next ❯

ServletRequest

The objective of a Servlet is to handle client request. There are two interfaces present in Servlet API, javax.servlet.ServletRequest and javax.servlet.http.HttpServletRequest to encapsulate client request. An object of ServletRequest is used to provide the client request information to a servlet such as content type, content length, parameter names and values, header informations, attributes etc .

Let's see an example to demonstrate the Servlet Request

index.html

<html>
<body>
<form action="MyServlet" method="post">
Name <input type="text" name="uname">
<input type="submit" value="ok">
</form>
</body>
</html>

MyServlet.java

MyServlet.java
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class MyServlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter pw = response.getWriter();
String s=request.getParameter("uname");
pw.println("Welcome"+s);
}
}

web.xml

<servlet>
<servlet-name>abc</servlet-name>
<servlet-class>com.javarace.MyServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name> abc</servlet-name>
<url-pattern>/MyServlet</url-pattern>
</servlet-mapping>

❮ Previous Next ❯

Follow Us





  Tutorials

Popular Links

Contact Us

address Plot No-N6/530,2ND Floor
Nayapalli,Jayadev Vihar
      Bhubaneswar-751015
      Email: info@silantechnology.com
      Phone: 0674-2361252
address
39877, sundale dr, apt#101, Fremont, California 94538, USA
       Phone: +1(262)388-7619

facebook twitter google linked in

© 2018 Silan Technology. All Rights Reserved