0% found this document useful (0 votes)
10 views2 pages

Url Rewriting

Uploaded by

Surya Dharshini
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views2 pages

Url Rewriting

Uploaded by

Surya Dharshini
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

index.

html

<form action="servlet1" method="post">

Name:<input type="text" name="userName"/><br/>

<input type="submit" value="go"/>

</form>

Servlet1

import java.io.*;

import javax.servlet.*;

import javax.servlet.http.*;

public class Servlet1 extends HttpServlet {

public void doPost(HttpServletRequest request, HttpServletResponse response){

try{

response.setContentType("text/html");

PrintWriter out = response.getWriter();

String n=request.getParameter("userName");

out.print("Welcome "+n);

response.sendRedirect("servlet2?name="+n); //URL Rewriting

out.close();

} catch(Exception e){System.out.println(e);}

Servlet2.java

import java.io.*;

import javax.servlet.*;

import javax.servlet.http.*;
public class Servlet2 extends HttpServlet {

public void doPost(HttpServletRequest request, HttpServletResponse response){

try {

response.setContentType("text/html");

PrintWriter out = response.getWriter();

out.println("Welcome " + request.getParameter("name"));

out.close();

} catch(Exception e){System.out.println(e);}

You might also like