<html>
<head>
<title>Home Page</title>
</head>
<body>
<h2 align="center">Welcome</h2>
<h3>This is your home page.</h3>
</body>
</html>
//ForwaredRequestDispatcher.java
package com.rajendra.servlets;
import java.io.PrintWriter;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class ForwaredRequestDispatcher extends HttpServlet {
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException
{
response.setContentType("text/html");
PrintWriter out=response.getWriter();
ServletContext context=getServletContext();
RequestDispatcher requestDispatcher=context.getRequestDispatcher("/index.html“);
requestDispatcher.forward(request, response);
}
}
//web.xml
<web-app>
<servlet>
<display-name>RequestDispatcherExample</display-name>
<servlet-name>RequestDispatcherExample</servlet-name>
<servlet-class>com.rajendra.servlets.RequestDispatcherExample</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>RequestDispatcherExample</servlet-name>
<url-pattern>/RequestDispatcherExample</url-pattern>
</servlet-mapping>
</web-app>
//before executing this program maintain the folder structure
No comments:
Post a Comment