What's new

Invoking Servlets from Html -A Simple Program For you

ebenzunlimited

Moderator
Html Code:



    <HTML>
        <head>
            <TITLE>INVOKING SERVLET FROM HTML</TITLE>
        </head>
    <BODY>
    <CENTER>
    <FORM name = "PostParam" method = "Post" action="http://localhost:8080/servlets-examples/servlet/serv">
    <TABLE>
    <tr>
    <td><B>Employee: </B> </td>
    <td><input type = "textbox" name="ename" size="25"
    value=""></td>
    </tr>
    <tr>
    <td><B>Phone: </B> </td>
    <td><input type = "textbox" name="phoneno" size="25"
    value=""></td>
    </tr>
    <tr>
    <td><b>Salary: </b></td>
    <td><input type="textbox" name="salary" size="25" value=""></td>
    </tr>
    <tr>
    <td><b>Id:</b></td>
    <td><input type="textbox" name="id" size="25" value=""></td>
    </tr>


    </TABLE>
    <INPUT type = "submit" value="Submit">
    </FORM>
    </CENTER>
    </body>
    </html>



Servlet Code:

    import java.io.*;
    import java.util.*;
    import javax.servlet.*;
    public class serv extends GenericServlet
    {
    public void service(ServletRequest request,ServletResponse response)throws ServletException,IOException
    {
    PrintWriter out=response.getWriter();
    String name=request.getParameter("ename");
    String phno=request.getParameter("phoneno");
    String sal=request.getParameter("salary");
    String id=request.getParameter("id");
    out.println("EmployeeName: "+name);
    out.println("Phone No:  "+phno);
    out.println("id:  "+id);
    out.println("Salary: "+salary);

    }
    }
 
Top