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

Session+Tracking+Using+URL+Re Writing

The document describes a simple web application that uses URL rewriting for session tracking. It includes an HTML form for user input, a servlet (HomePage) that processes the input and redirects to a product page, and another servlet (ProductPage) that displays a welcome message using the user's name. The application demonstrates how to pass parameters between pages using URL query strings.

Uploaded by

Akash Yadav
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)
29 views6 pages

Session+Tracking+Using+URL+Re Writing

The document describes a simple web application that uses URL rewriting for session tracking. It includes an HTML form for user input, a servlet (HomePage) that processes the input and redirects to a product page, and another servlet (ProductPage) that displays a welcome message using the user's name. The application demonstrates how to pass parameters between pages using URL query strings.

Uploaded by

Akash Yadav
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

Session Tracking Using URL-ReWriting:

index.html
-----------
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<form method="post" action="home">
Name:<Input type="text"
name="nametxtbox"><br>
<input type="submit" value="submit">
</form>
</body>
</html>
===============================
Homepage.java file
------------------
package t.a.w;

import java.io.IOException;
import java.io.PrintWriter;

import jakarta.servlet.ServletException;
import
jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import
jakarta.servlet.http.HttpServletRequest;
import
jakarta.servlet.http.HttpServletResponse;

@WebServlet("/home")
public class HomePage extends HttpServlet{
@Override
protected void
doPost(HttpServletRequest req,
HttpServletResponse resp) throws
ServletException, IOException {

resp.setContentType("text/html");
PrintWriter po=resp.getWriter();
String
n=req.getParameter("nametxtbox");
po.println(n+" You are on
HomePage..");

po.println("<a
href='product?savedName="+n+"'>Go To
Product Page!!</a>");
}
}

====================================
ProductPage.java
--------------------
package t.a.w;

import java.io.IOException;
import java.io.PrintWriter;

import jakarta.servlet.ServletException;
import
jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import
jakarta.servlet.http.HttpServletRequest;
import
jakarta.servlet.http.HttpServletResponse;

@WebServlet("/product")
public class ProductPage extends
HttpServlet{

@Override
protected void
doGet(HttpServletRequest req,
HttpServletResponse resp) throws
ServletException, IOException {

resp.setContentType("text/html");
PrintWriter po=resp.getWriter();
String
n=req.getParameter("savedName");
po.println(n+" Welcome on Product
Page!!");
}

=====================================
======

You might also like