SERVLET FIRST @@@@@@@@@@@@@@@@@@
package org.com;
import java.io.*; import java.net.*;
import javax.servlet.*; import javax.servlet.http.*;
public class Servlet_1 extends HttpServlet {
int a,b,c,d,sum1 ;
RequestDispatcher rd;
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { a=Integer.parseInt(request.getParameter("txtT1")); b=Integer.parseInt(request.getParameter("txtT2")); c=Integer.parseInt(request.getParameter("txtT3")); int sum1=a+b+c; request.setAttribute("ID", "101"); request.setAttribute("NAME", "MUKESH KUMAR PRASAD"); request.setAttribute("AGE", "21"); request.setAttribute("ADDRESS", "12"); request.setAttribute("PHONE", "9871282091"); request.setAttribute("CITY", "INDIAN"); response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); rd=request.getRequestDispatcher("Servlet_2"); rd.forward(request,response); out.println("<html>"); out.println("<head>"); out.println("<title>Servlet Servlet_1</title>"); out.println("</head>"); out.println("<body>"); out.println("<h1>Servlet Servlet_1 at " + request.getContextPath () + "</h1>"); out.println("</body>"); out.println("</html>"); out.close(); } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response); } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response); } public String getServletInfo() { return "Short description"; }
}
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
SECOND SERVLET Servlet_2.java
package org.com;
import java.io.*; import java.net.*;
import javax.servlet.*; import javax.servlet.http.*;
public class Servlet_2 extends HttpServlet {
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { int sum1; response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); sum1=Integer.parseInt(request.getParameter("txtT1"))
+Integer.parseInt(request.getParameter("txtT2")) +Integer.parseInt(request.getParameter("txtT3")); out.println(""); out.println(""); out.println("
out.println("<h1>Servlet Servlet_2 at " + request.getContextPath () + "</h1>"); out.println(" Servlet_2 "); out.println(sum1); String ID = (String)request.getAttribute("ID"); String NAME = (String)request.getAttribute("NAME"); String AGE=(String)request.getAttribute("AGE"); String ADDRESS=(String)request.getAttribute("ADDRESS"); String PHONE=(String)request.getAttribute("PHONE"); String CITY =(String)request.getAttribute("CITY"); out.println(ID+" "+" "+NAME+" "+AGE+" "+ADDRESS+" "+PHONE+" "+CITY); out.println("</body>"); out.println("</html>"); out.close(); } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response); } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response); } public String getServletInfo() { return "Short description"; } }
SERVLET FIRST @@@@@@@@@@@@@@@@@@
package org.com;
import java.io.*; import java.net.*;
import javax.servlet.*; import javax.servlet.http.*;
public class Servlet_1 extends HttpServlet {
int a,b,c,d,sum1 ;
RequestDispatcher rd;
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { a=Integer.parseInt(request.getParameter("txtT1")); b=Integer.parseInt(request.getParameter("txtT2")); c=Integer.parseInt(request.getParameter("txtT3")); int sum1=a+b+c; request.setAttribute("ID", "101"); request.setAttribute("NAME", "MUKESH KUMAR PRASAD"); request.setAttribute("AGE", "21"); request.setAttribute("ADDRESS", "12"); request.setAttribute("PHONE", "9871282091"); request.setAttribute("CITY", "INDIAN"); response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); rd=request.getRequestDispatcher("Servlet_2"); rd.forward(request,response); out.println("<html>"); out.println("<head>"); out.println("<title>Servlet Servlet_1</title>"); out.println("</head>"); out.println("<body>"); out.println("<h1>Servlet Servlet_1 at " + request.getContextPath () + "</h1>"); out.println("</body>"); out.println("</html>"); out.close(); } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response); } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response); } public String getServletInfo() { return "Short description"; }
}
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
SECOND SERVLET Servlet_2.java
package org.com;
import java.io.*; import java.net.*;
import javax.servlet.*; import javax.servlet.http.*;
public class Servlet_2 extends HttpServlet {
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { int sum1; response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); sum1=Integer.parseInt(request.getParameter("txtT1"))
+Integer.parseInt(request.getParameter("txtT2")) +Integer.parseInt(request.getParameter("txtT3")); out.println(""); out.println(""); out.println("
out.println("<h1>Servlet Servlet_2 at " + request.getContextPath () + "</h1>"); out.println(" Servlet_2 "); out.println(sum1); String ID = (String)request.getAttribute("ID"); String NAME = (String)request.getAttribute("NAME"); String AGE=(String)request.getAttribute("AGE"); String ADDRESS=(String)request.getAttribute("ADDRESS"); String PHONE=(String)request.getAttribute("PHONE"); String CITY =(String)request.getAttribute("CITY"); out.println(ID+" "+" "+NAME+" "+AGE+" "+ADDRESS+" "+PHONE+" "+CITY); out.println("</body>"); out.println("</html>"); out.close(); } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response); } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response); } public String getServletInfo() { return "Short description"; } }