0% found this document useful (0 votes)
66 views6 pages

URL Rewriting Example with Servlets

This document contains source code for a URL rewriting sample using Java servlets. It includes the code for an index.html page with a form that submits to Servlet1. Servlet1 gets the user name parameter, prints a welcome message, and links to Servlet2 passing the user name. Servlet2 prints a greeting using the user name parameter. The source code includes comments identifying the author and class.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
66 views6 pages

URL Rewriting Example with Servlets

This document contains source code for a URL rewriting sample using Java servlets. It includes the code for an index.html page with a form that submits to Servlet1. Servlet1 gets the user name parameter, prints a welcome message, and links to Servlet2 passing the user name. Servlet2 prints a greeting using the user name parameter. The source code includes comments identifying the author and class.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Pua, Lance Christian L.

2ITB May 6, 2019

Screenshots Output:
Pua, Lance Christian L. 2ITB May 6, 2019
Pua, Lance Christian L. 2ITB May 6, 2019

Source Code:

[Link]
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>URL Rewriting Sample</title>
<link rel="stylesheet" href="css/[Link]">
</head>
<body>
<h1> Lance Pua's URL Rewriting</h1>
<form action="servlet1">
Name:<input type="text" name="userName"/><br/>
<input type="submit" value="submit"/>
</form>
</body>
</html>

[Link]

//PUA,LANCE CHRISTIAN L.

//2ITB

//URL WRIRITING

package [Link];

import [Link];

import [Link];

import [Link];

import [Link];

import [Link].*;

@WebServlet("/servlet1")

public class Servlet1 extends HttpServlet {

private static final long serialVersionUID = 1L;

public void doGet(HttpServletRequest request, HttpServletResponse response){


Pua, Lance Christian L. 2ITB May 6, 2019

try{

[Link]("text/html");

PrintWriter out = [Link]();

String n=[Link]("userName");

[Link]("Welcome "+n);

[Link]("<p><a href='servlet2?uname="+n+"'>continue</a>");

[Link]();

catch(Exception e)

[Link](e);

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws


ServletException, IOException {

}
Pua, Lance Christian L. 2ITB May 6, 2019

[Link]

//PUA,LANCE CHRISTIAN L.

//2ITB

//URL WRIRITING

package [Link];

import [Link];

import [Link];

import [Link];

import [Link];

import [Link];

import [Link];

import [Link];

@WebServlet("/servlet2")

public class Servlet2 extends HttpServlet {

private static final long serialVersionUID = 1L;

protected void doGet(HttpServletRequest request, HttpServletResponse response)


throws ServletException, IOException {

try{

[Link]("text/html");

PrintWriter out = [Link]();

String n=[Link]("uname");

[Link]("<p>Hello "+n);
Pua, Lance Christian L. 2ITB May 6, 2019

[Link]();

catch(Exception e)

[Link](e);

protected void doPost(HttpServletRequest request, HttpServletResponse response)


throws ServletException, IOException {

You might also like