In this example, we will show how a parameter is passed to a servlet in request object from html page.
index.html
<form method="post" action="check">
Name <input type="text" name="user" >
<input type="submit" value="submit">
</form>
web.xml
<servlet>
        <servlet-name>check</servlet-name>
        <servlet-class>MyServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>check</servlet-name>
        <url-pattern>/check</url-pattern>
    </servlet-mapping>
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;charset=UTF-8");
        PrintWriter out = response.getWriter();
        try {
           
            String user=request.getParameter("user");
            out.println("<h2> Welcome "+user+"</h2>");
        } finally {            
            out.close();
        }
    }
}


Output




1 comments :


  1. Thinking to upgrade and update your Website & App? Well you deserve what you want, when you pay for it! Therefpre InnovationM UK is at your service. Opening doors for advancement to get your milestone easily. InnovationM UK is an app development company in birmingham, which is no.1 in the matter of trust and authenticity among app design companies in london. Whether it's website development in luton, mobile app agency in manchester or app design company in london, we have everything to offer. Looking forward for iphone app development in birmingham, we got your back! InnovationM UK covers you with app design agency in uk as best website design company in luton, mobile app development services in birmingham, mobile app development company in birmingham, mobile development agency in london. As the dgital era is approaching, mobile app development services in birmingham will grow much denser also development of iphone app in derby. There we stay to full-fill, as your trusted mobile agency in uk. So whenever you wish to get your dream app design agency in london, web design company in derby, app design agency in london, Best Software development company in London or app developers sheffield InnovationM UK is right by your side with the best app developers in birmingham. Cheers to your success!

    And also popularly known forsoftware design agency derby, android app design agency derby, mobile app design agency derby, website development in cambridge birmingham, app developers luton, app design bristol, app development luton, software design company derby, iphone app development company derby, bespoke app development derby, ios app development company derby, software development company brighton, mobile app design derby, android app development company in derby, software app development derby, mobile app development company derby, app agency oxford, web app development bristol development agency brighton, ios app development derby, iphone app development derby,UK.

    ReplyDelete

 
Top