1. A Jsp File
2. Deployment Descriptor (web.xml)
3. A Servlet File (Normal Java File)
Jsp File (index.jsp)
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
Servlet File (test1.java)
Note : Here doGet/doPost/service method can be used.But I used here doGet(),becacuse the form action method is GET in index.jsp. So , I used doGet() in this example. But service method can use for both POST/GET method .But you can use any of these.
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String name=request.getParameter("txtname");
out
.println("");
out.println("");
out.println("
out.print("
Hi I am
");out.print("
"+name+"
");out.println(" ");
out.println("");
out.flush();
out.close();
}
Deployment Descriptor (Web.xml)
Note: In web.xml url-pattern is the path for browser ,so any name can be used (not /test1). we need
This is a simple Example for Communicate a servlet from jsp by passing a value Name or any Data.Enjoy..............the flavor of JAVA.
Posted By:- javadevelopersguide
Follow :- javadevelopersguide.blogspot.com
No comments:
Post a Comment