0% found this document useful (0 votes)
19 views

Prog 6

1. A new Java web application project named "program6" is created. 2. A servlet named "sendredirect" is created that redirects requests to another servlet called "prog6". 3. The "prog6" servlet is created to display an HTML page with text indicating that the URL has changed and welcoming the user to Java.

Uploaded by

Shounak Basu
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

Prog 6

1. A new Java web application project named "program6" is created. 2. A servlet named "sendredirect" is created that redirects requests to another servlet called "prog6". 3. The "prog6" servlet is created to display an HTML page with text indicating that the URL has changed and welcoming the user to Java.

Uploaded by

Shounak Basu
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Program 5

1. New project -> JAVA WEB ->Web application ->(Give a name as program6) finish
2. Right click on project -> new -> servlet ->give the classname as sendredirect
3. code as given in sendredirect.java.
4. Right click on project -> new -> servlet ->give the classname as prog6
5. code as given in prog6.java.
6. build the code and run.
7. in the browser give the servlet name sendredirect after the url.

sendredirect.java
import java.io.*;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class sendredirect extends HttpServlet {

@Override
public void doGet(HttpServletRequest req,HttpServletResponse res)throws ServletException,
IOException {
res.sendRedirect("prog6");
}

}

prog6.java

import java.io.*;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class prog6 extends HttpServlet {

@Override
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException,
IOException
{

res.setContentType("text/html");
PrintWriter pw = res.getWriter();
pw.println("<html><title>SendRedirect Demo</title>");
pw.println("<body>");
pw.println("<b><h1>Please Notice Your URL has changed</h1></b><br />");
pw.println("<h2>I am another Servlet to response you</h2><br />");
pw.println("<b><h1>Welcome to JAVA</h1></b>");
pw.println("</body></html>");
pw.close();
}

}

You might also like