//index.jsp
<%@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>index.jsp</title>
</head>
<body>
<h3> Message from the index.jsp </h3>
</body>
</html>
//MyServlet.java
package com.rajendra.servlets;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class MyServlet extends HttpServlet {
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head>");
out.println("</head>");
out.println("<body>");
out.println("currently in the MyServlet ");
RequestDispatcher rd = request.getRequestDispatcher("/index.jsp");
rd.include(request, response);
out.println("back to the MyServlet ");
out.println("</body>");
out.println("</html>");
}
}
- //maintain the folder structure
- create WEB-INF folder
- under WEB-INF folder create "classes" and web.xml file
- go to classes and paste the class file of MyServlet.java
- to to WEB-INF folder and open web.xml in a note pad , paste the following code:
<web-app>
<servlet>
<servlet-name>MyServlet</servlet-name>
<servlet-class>com.rajendra.servlets.MyServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>MyServlet</servlet-name>
<url-pattern>/MyServlet</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>MyServlet</welcome-file>
</welcome-file-list>
No comments:
Post a Comment