index.jsp (JSP File)
___________________________________________
^%@page contentType="text/html" pageEncoding="UTF-8"%#
^!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd"#
^html#
^head#
^meta http-equiv="Content-Type" content="text/html; charset=UTF-8"#
^title#JSP Page^/title#
^/head#
^body#
^B#Please Sign Our Guestbook ^/B#^P#
^FORM ACTION="http://localhost:8084/DemoServlet/servlet" method="get"#
^TABLE border="1" cellpadding="2" cellspacing="2" style="font: 11px verdana" #
^TR#
^TD#
Full Name:
^/TD#
^TD#
^INPUT TYPE="text" NAME="name"value="" #
^/TD#
^/TR#
^TR#
^TD#
Email Address
^/TD#
^TD#
^INPUT TYPE="text" NAME="email"value=""#
^/TD#
^/TR#
^TR#
^TD colspan="2"#
Message:^BR# ^TEXTAREA NAME="message" ROWS="3" COLS="35"# ^/TEXTAREA#
^/TD#
^/TR#
^TR#
^TD colspan="2" #
^INPUT TYPE="submit" name=" submit" value="Submit"#
^/TD#
^/TR#
^/TABLE#
^/FORM#
^/body#
^/html#
____________________________________________________
Servlet code.... Servlet name --# servlet
package spackage;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class servlet extends HttpServlet {
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
}
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
String name,email,message;
name=request.getParameter("name");
email=request.getParameter("email");
message=request.getParameter("message");
out.println("^html#");
out.println("^body#");
out.println("^h1# Welcome ^B#" + name + " ^/B# ^/h1# ^BR#");
out.println("a mail has been sent to " + email + "^BR#");
out.println("You said " + message + "^BR#");
out.println("^/body#");
out.println("^/html#");
processRequest(request, response);
out.flush();
out.close();
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
@Override
public String getServletInfo() {
return "Short description";
}// ^/editor-fold#
}
No comments:
Post a Comment