Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • ServletRequest Interface with example

    • 0
    • 1
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 163
    Comment on it

    The ServletRequest interface have many methods to handle client requests to access a servlet. It is used for access client requests in servlet. HttpServletRequest extends to ServletRequest.

    alt text


    Below example will help you to batter understand :

    web.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app>
    <servlet>
    <servlet-name>myservlet</servlet-name>
    <servlet-class>ServletDemo</servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name>myservlet</servlet-name>
    <url-pattern>/servlet</url-pattern>
    </servlet-mapping>
    
    </web-app>
    

    index.html

    <form action="servlet" method="get">  
    <input type="text" name="name"><br>  
    <input type="submit" value="login">  
    </form>  
    

    ServletDemo.java

    import javax.servlet.http.*;  
    import javax.servlet.*;  
    import java.io.*;  
    public class ServletDemo extends HttpServlet{  
    public void doGet(HttpServletRequest req,HttpServletResponse res)  
    throws ServletException,IOException  
    {  
    res.setContentType("text/html");  
    PrintWriter out=res.getWriter();  
    
    String name=req.getParameter("name");
    out.println("Welcome "+name);  
    
    out.close();  
    }}  
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: