aspose file tools*
The moose likes Servlets and the fly likes how to find which servlet invoked the next Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "how to find which servlet invoked the next" Watch "how to find which servlet invoked the next" New topic
Author

how to find which servlet invoked the next

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
-----------------------------------------------------------------form 1 used to submit name and age
-----------------------------------------------------------------
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF">
<form action="http://127.0.0.1:8080/servlet/hidden" method=get>
Name<input type=text name=na><br>
Age<input type=text name=ag><br>
<input type=submit name=submit value=submit>
</BODY>
</HTML>
*****************************************************************
servlet to retrive the values and to act as an intermediate servlet
*****************************************************************
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class hidden extends HttpServlet
{
PrintWriter pw;
public void doGet(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException
{
pw=res.getWriter();
res.setContentType("text/html");
String s1=req.getParameter("na");
String s2=req.getParameter("ag");
String s3=req.getRequestURI();
StringBuffer s4=HttpUtils.getRequestURL(req);
pw.println("<html><body>");
pw.println("<form action=http://127.0.0.1:8080/servlet/hide method=get>");
pw.println("age <input type=text value="+s2+">");
pw.println("<input type=hidden value="+s1+" name=hi>");
pw.println("<input type=submit value=submit>");
pw.println("</form>");
pw.println("<h1><a href=http://127.0.0.1:8080/servlet/hide?hi="+s1+"> Welcome to hidden Field </a></h1>");
pw.println("<br>"+s3);
pw.println("<br>"+s4);
pw.println("</body></html>");
*****************************************************************
servlet which acepts request from previous servlet
****************************************************************
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class hide extends HttpServlet
{
PrintWriter pw;
public void doGet(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException
{
pw=res.getWriter();
res.setContentType("text/html");
String s1=req.getParameter("hi");
StringBuffer s3=HttpUtils.getRequestURL(req);
String s2=req.getRequestURI();
String s4=req.getServletPath();
if((s3.toString()).equals("http://127.0.0.1:8080/servlet/hide"))
{
pw.println("<html><body>");
pw.println(s1);
pw.println("<br>"+s3);
pw.println("<br>"+s2);
pw.println("<br>"+s4);
pw.println("</body></html>");
}
else
{
res.sendRedirect("HTTP://127.0.0.1:/index.html");
}
}
}

**********************************************************************************************************************************
i have tried using get req uri and get request url.
it gave me the current servlet url ,in which i included these methods. but iam looking for a method. which specifies the reffer which invoked the servlet.
ie i should get the url of the html page in my first servlet and
the url of first servlet in second.
hide.java gave the following result.
http://127.0.0.1:8080/servlet/hide
-------------------------------------
but what i want is http://127.0.0.1:8080/servlet/hidden
who can i find the reffer in a servlet.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: how to find which servlet invoked the next