<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://jexp.ru/index.php?action=history&amp;feed=atom&amp;title=Java_Tutorial%2FServlet%2FRedirect</id>
		<title>Java Tutorial/Servlet/Redirect - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://jexp.ru/index.php?action=history&amp;feed=atom&amp;title=Java_Tutorial%2FServlet%2FRedirect"/>
		<link rel="alternate" type="text/html" href="http://jexp.ru/index.php?title=Java_Tutorial/Servlet/Redirect&amp;action=history"/>
		<updated>2026-04-08T16:19:02Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://jexp.ru/index.php?title=Java_Tutorial/Servlet/Redirect&amp;diff=4936&amp;oldid=prev</id>
		<title>Admin: 1 версия</title>
		<link rel="alternate" type="text/html" href="http://jexp.ru/index.php?title=Java_Tutorial/Servlet/Redirect&amp;diff=4936&amp;oldid=prev"/>
				<updated>2010-06-01T05:07:03Z</updated>
		
		<summary type="html">&lt;p&gt;1 версия&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Версия 05:07, 1 июня 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	<entry>
		<id>http://jexp.ru/index.php?title=Java_Tutorial/Servlet/Redirect&amp;diff=4935&amp;oldid=prev</id>
		<title> в 17:44, 31 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://jexp.ru/index.php?title=Java_Tutorial/Servlet/Redirect&amp;diff=4935&amp;oldid=prev"/>
				<updated>2010-05-31T17:44:27Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==  Redirect Servlet Based on Path Info And Query String ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
import java.io.*;&lt;br /&gt;
import javax.servlet.*;&lt;br /&gt;
import javax.servlet.http.*;&lt;br /&gt;
import java.util.*;&lt;br /&gt;
public class MyServlet extends HttpServlet {&lt;br /&gt;
  public void doGet(HttpServletRequest req, HttpServletResponse res)&lt;br /&gt;
                               throws ServletException, IOException {&lt;br /&gt;
    // Determine the site where they want to go&lt;br /&gt;
    String site = req.getPathInfo();&lt;br /&gt;
    String query = req.getQueryString();&lt;br /&gt;
    // Handle a bad request&lt;br /&gt;
    if (site == null) {&lt;br /&gt;
      res.sendError(res.SC_BAD_REQUEST, &amp;quot;Extra path info required&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    // Cut off the leading &amp;quot;/&amp;quot; and append the query string&lt;br /&gt;
    // We&amp;quot;re assuming the path info URL is always absolute&lt;br /&gt;
    String url = site.substring(1) + (query == null ? &amp;quot;&amp;quot; : &amp;quot;?&amp;quot; + query);&lt;br /&gt;
    // Log the requested URL and redirect&lt;br /&gt;
    log(url);  // or write to a special file&lt;br /&gt;
    res.sendRedirect(url);&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==  Redirect Servlet by Setting Response Location ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
import java.io.*;&lt;br /&gt;
import javax.servlet.*;&lt;br /&gt;
import javax.servlet.http.*;&lt;br /&gt;
import java.util.*;&lt;br /&gt;
public class MyServlet extends HttpServlet {&lt;br /&gt;
  Vector sites = new Vector();&lt;br /&gt;
  Random random = new Random();&lt;br /&gt;
  public void init() throws ServletException {&lt;br /&gt;
    sites.addElement(&amp;quot;http://www.jexp.ru/Code/Java/CatalogJava.htm&amp;quot;);&lt;br /&gt;
    sites.addElement(&amp;quot;http://www.jexp.ru/Tutorial/Java/CatalogJava.htm&amp;quot;);&lt;br /&gt;
    sites.addElement(&amp;quot;http://www.jexp.ru/Article/Java/CatalogJava.htm&amp;quot;);&lt;br /&gt;
    sites.addElement(&amp;quot;http://www.jexp.ru/Product/Java/CatalogJava.htm&amp;quot;);&lt;br /&gt;
  }&lt;br /&gt;
  public void doGet(HttpServletRequest req, HttpServletResponse res)&lt;br /&gt;
                               throws ServletException, IOException {&lt;br /&gt;
    res.setContentType(&amp;quot;text/html&amp;quot;);&lt;br /&gt;
    PrintWriter out = res.getWriter();&lt;br /&gt;
    int siteIndex = Math.abs(random.nextInt()) % sites.size();&lt;br /&gt;
    String site = (String)sites.elementAt(siteIndex);&lt;br /&gt;
    res.setStatus(res.SC_MOVED_TEMPORARILY);&lt;br /&gt;
    res.setHeader(&amp;quot;Location&amp;quot;, site);&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;/div&gt;</summary>
			</entry>

	</feed>