jsp 中的301重定向帖子(转帖)

这位用的环境和需求和我的差不多,好像可以试一试。今天我作的重定向有的检测网站返回301,有的返回500

今天再把下面帖子的方法试试。

转帖:(转自:http://www.caucho.com/support/resin-interest/0510/0009.html

**************************************************************************************************************************

Re: 301 redirect

 · This message: [ Message body ] [ More options ]

 · Related messages: [ Next message ] [ Previous message ] [ In reply to ]

From: Thomas Moorer <thomas.moorer@xxx.com>

Date: Sat Oct 22 2005 - 04:44:52 PDT

Hi All,

Never mind ? I figured it out. I?ll post the solution in case anyone else

needs it later.

Old jsp redirecting to new location.

 try {

     response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);

     response.setHeader( "Location", "/buy-a-business/index.jsp" );

     response.setHeader( "Connection", "close" );

     return;

 } catch (Exception e) {}

Proof in log file. Highlighted in red.

[2005/10/22 07:37:53 - INFO] 127.0.0.1 : /buyers/index.jsp loaded in 2.292

seconds.

[2005/10/22 07:37:53.060] [www-2005.sunbeltnetwork.com, 11] HTTP/1.1 301

Moved Permanently

[2005/10/22 07:37:53.066] [www-2005.sunbeltnetwork.com, 11] Location:

/buy-a-business/index.jsp

[2005/10/22 07:37:53.067] [www-2005.sunbeltnetwork.com, 11] Connection:

close

[2005/10/22 07:37:53.067] [www-2005.sunbeltnetwork.com, 11] Content-Type:

text/html

[2005/10/22 07:37:53.068] [www-2005.sunbeltnetwork.com, 11]

Transfer-Encoding: chunked

[2005/10/22 07:37:53.085] [www-2005.sunbeltnetwork.com, 11] keepalive

[2005/10/22 07:37:53.086] [www-2005.sunbeltnetwork.com, 11] read timeout

[2005/10/22 07:37:53.091] closing connection

TcpConnection[id=resin-tcp-connection-www-tcm.sunbeltnetwork.com:80-23,socke

t=JniSocketImpl$12218796[41838600],port=Port[www-tcm.sunbeltnetwork.com:80]]

, total=10

[2005/10/22 07:37:53.109] starting connection

TcpConnection[id=resin-tcp-connection-www-tcm.sunbeltnetwork.com:80-39,socke

t=JniSocketImpl$8441961[41834504],port=Port[www-tcm.sunbeltnetwork.com:80]],

total=10

[2005/10/22 07:37:53.110] [www-2005.sunbeltnetwork.com, 19] GET

/buy-a-business/index.jsp HTTP/1.1

[2005/10/22 07:37:53.110] [www-2005.sunbeltnetwork.com, 19] Accept: */*

[2005/10/22 07:37:53.110] [www-2005.sunbeltnetwork.com, 19] Accept-Language:

en

[2005/10/22 07:37:53.110] [www-2005.sunbeltnetwork.com, 19] Accept-Encoding:

gzip, deflate

[2005/10/22 07:37:53.110] [www-2005.sunbeltnetwork.com, 19] Cookie:

ANONID=LZ3ZE1CY4LERDFSYCSORMMHP47JRP7APWTWIB5C9; JSESSIONID=JmHyfpl_hX57gXgy

[2005/10/22 07:37:53.110] [www-2005.sunbeltnetwork.com, 19] User-Agent:

Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/412.7 (KHTML, like

Gecko) Safari/412.5

[2005/10/22 07:37:53.110] [www-2005.sunbeltnetwork.com, 19] Connection:

keep-alive

[2005/10/22 07:37:53.110] [www-2005.sunbeltnetwork.com, 19] Host:

www-tcm.sunbeltnetwork.com

[2005/10/22 07:37:53.120] [www-2005.sunbeltnetwork.com, 19] HTTP/1.1 200 OK

[2005/10/22 07:37:53.120] [www-2005.sunbeltnetwork.com, 19] Content-Type:

text/html

[2005/10/22 07:37:53.120] [www-2005.sunbeltnetwork.com, 19]

Transfer-Encoding: chunked

[2005/10/22 07:37:53.121] [19] chunk: 1424

[2005/10/22 07:37:53.122] [19] chunk: 3813

[2005/10/22 07:37:53.123] [19] chunk: 2526

[2005/10/22 07:37:53.148] [19] chunk: 2078

[2005/10/22 07:37:53 - INFO] 127.0.0.1 : /buy-a-business/index.jsp loaded in

0.037 seconds.

Thomas

--

Thomas C. Moorer, Jr. ~ IT Manager

103 Church Street

Mount Pleasant, SC 29464

Sunbelt Business Advisors Network, LLC

http://www.sunbeltnetwork.com

From: Thomas Moorer <thomas.moorer@xxx.com>

Reply-To: "resin-interest@xxx.com" <resin-interest@xxx.com>

Date: Fri, 21 Oct 2005 18:01:25 -0400

To: "resin-interest@xxx.com" <resin-interest@xxx.com>

Conversation: 301 redirect

Subject: Re: 301 redirect

Yong,

Thanks for the reply...

I believe it would be better to do the 301 (Moved Permanently) than the

rewrite. I want the Search Engines to know I have renamed my pages (but not

reduce my page ranking - hopefully they will give be a better page rank over

time) (I know this is a lot of marketing talk in a techie forum, but I am

trying to solve essentially a marketing problem with technology). Anyhoo...

There wasn't a matching function in the HttpServletRedirect class for your

suggestion, so I am trying to come up with a comparable solution (see mine

below). I believe this should work correctly. I mean, it obviously will

redirect to the new page - that works.

I am attmepting to redirect from /buyers/index.jsp to /buy-a-business.jsp.

The code below is in /buyers/index.jsp

 try {

     response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);

     response.sendRedirect("/buy-a-business/index.jsp");

     return;

 } catch (Exception e) {}

My remaining question still pertains to the Status code. I have full logging

on and I'm not seeing a 301 Status code being returned... Below is a snippet

from the log file. It seems to from a 302 to a 200 code highlighted in red

(if you?ve got an html client).

[2005/10/21 17:57:04.842] starting connection

TcpConnection[id=resin-tcp-connection-www-tcm.sunbeltnetwork.com:80-25,socke

t=JniSocketImpl$15241174[125306376],port=Port[www-tcm.sunbeltnetwork.com:80]

], total=10

[2005/10/21 17:57:04.842] [www-2005.sunbeltnetwork.com, 12] GET

/buyers/index.jsp HTTP/1.1

[2005/10/21 17:57:04.842] [www-2005.sunbeltnetwork.com, 12] Accept: */*

[2005/10/21 17:57:04.843] [www-2005.sunbeltnetwork.com, 12] Accept-Language:

en

[2005/10/21 17:57:04.843] [www-2005.sunbeltnetwork.com, 12] Accept-Encoding:

gzip, deflate

[2005/10/21 17:57:04.843] [www-2005.sunbeltnetwork.com, 12] Cookie:

ANONID=LZ3ZE1CY4LERDFSYCSORMMHP47JRP7APWTWIB5C9; JSESSIONID=CzyD9BkGE3-3Awbt

[2005/10/21 17:57:04.843] [www-2005.sunbeltnetwork.com, 12] User-Agent:

Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/412.7 (KHTML, like

Gecko) Safari/412.5

[2005/10/21 17:57:04.843] [www-2005.sunbeltnetwork.com, 12] Connection:

keep-alive

[2005/10/21 17:57:04.843] [www-2005.sunbeltnetwork.com, 12] Host:

www-tcm.sunbeltnetwork.com

[2005/10/21 17:57:04.846] [www-2005.sunbeltnetwork.com, 12] HTTP/1.1 302

Found

[2005/10/21 17:57:04.846] [www-2005.sunbeltnetwork.com, 12] Location:

http://www-tcm.sunbeltnetwork.com/buy-a-business/index.jsp

[2005/10/21 17:57:04.846] [www-2005.sunbeltnetwork.com, 12] Content-Type:

text/html

[2005/10/21 17:57:04.846] [www-2005.sunbeltnetwork.com, 12] Content-Length:

96

[2005/10/21 17:57:04.846] [12] chunk: 96

[2005/10/21 17:57:04 - INFO] 127.0.0.1 : /buyers/index.jsp loaded in 0.026

seconds.

[2005/10/21 17:57:04.872] [www-2005.sunbeltnetwork.com, 12] keepalive

[2005/10/21 17:57:04.872] [www-2005.sunbeltnetwork.com, 12] read timeout

[2005/10/21 17:57:04.872] closing connection

TcpConnection[id=resin-tcp-connection-www-tcm.sunbeltnetwork.com:80-25,socke

t=JniSocketImpl$15241174[125306376],port=Port[www-tcm.sunbeltnetwork.com:80]

], total=10

[2005/10/21 17:57:04.873] starting connection

TcpConnection[id=resin-tcp-connection-www-tcm.sunbeltnetwork.com:80-25,socke

t=JniSocketImpl$15241174[125306376],port=Port[www-tcm.sunbeltnetwork.com:80]

], total=10

[2005/10/21 17:57:04.873] [www-2005.sunbeltnetwork.com, 12] GET

/buy-a-business/index.jsp HTTP/1.1

[2005/10/21 17:57:04.873] [www-2005.sunbeltnetwork.com, 12] Accept: */*

[2005/10/21 17:57:04.873] [www-2005.sunbeltnetwork.com, 12] Accept-Language:

en

[2005/10/21 17:57:04.873] [www-2005.sunbeltnetwork.com, 12] Accept-Encoding:

gzip, deflate

[2005/10/21 17:57:04.873] [www-2005.sunbeltnetwork.com, 12] Cookie:

ANONID=LZ3ZE1CY4LERDFSYCSORMMHP47JRP7APWTWIB5C9; JSESSIONID=CzyD9BkGE3-3Awbt

[2005/10/21 17:57:04.873] [www-2005.sunbeltnetwork.com, 12] User-Agent:

Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/412.7 (KHTML, like

Gecko) Safari/412.5

[2005/10/21 17:57:04.873] [www-2005.sunbeltnetwork.com, 12] Connection:

keep-alive

[2005/10/21 17:57:04.873] [www-2005.sunbeltnetwork.com, 12] Host:

www-tcm.sunbeltnetwork.com

[2005/10/21 17:57:04.874] using cache: /head.jsp

[2005/10/21 17:57:04.875] [www-2005.sunbeltnetwork.com, 12] HTTP/1.1 200 OK

[2005/10/21 17:57:04.875] [www-2005.sunbeltnetwork.com, 12] Content-Type:

text/html

[2005/10/21 17:57:04.875] [www-2005.sunbeltnetwork.com, 12]

Transfer-Encoding: chunked

I don?t know if I have the status set in the right place / right sequence.

Can anyone help me out?

Thomas

--

Thomas C. Moorer, Jr. ~ IT Manager

103 Church Street

Mount Pleasant, SC 29464

Sunbelt Business Advisors Network, LLC

http://www.sunbeltnetwork.com

> From: Yong Bakos <yongb@xxx.com>

> Reply-To: "resin-interest@xxx.com" <resin-interest@xxx.com>

> Date: Mon, 17 Oct 2005 14:20:54 -0600

> To: <resin-interest@xxx.com>

> Conversation: 301 redirect

> Subject: RE: 301 redirect

>

>

> I'm a bit confused as to why you don't just use the filter or roll your

> own and use the addHeader(HttpServletResponse.SC_MOVED_PERMANENTLY,

> newPath) method in HttpServletResponse.

>

>

> -----Original Message-----

> From: owner-resin-interest@xxx.com

> [mailto:owner-resin-interest@xxx.com] On Behalf Of Thomas Moorer

> Sent: Monday, October 17, 2005 1:57 PM

> To: resin-interest@xxx.com

> Subject: Re: 301 redirect

>

> After reading my original message, I feel I need to clarify one point as

> well as ask and additional question:

>

> Clarification:

>

> I have my web.xml file configured to use the rewrite filter, but the

> scenario below is not in use. It is just an example of how I might use

> the rewrite filter to handle a directory name change.

>

> Question:

>

> When a rewrite filter actually does the move what is the underlying http

> status code that is returned? Obviously 301 is the one I would prefer...

>

> 301 Moved Permanently

> 302 Found

> 303 See Other

> 304 Not Modified

> 305 Use Proxy

> 306 (Unused)

> 307 Temporary Redirect

>

> Thomas

>

> --

>

> Thomas C. Moorer, Jr. ~ IT Manager

> 103 Church Street

> Mount Pleasant, SC 29464

> Sunbelt Business Advisors Network, LLC

> http://www.sunbeltnetwork.com

>

>

>

> ________________________________

>

> From: Thomas Moorer <thomas.moorer@xxx.com>

> Reply-To: "resin-interest@xxx.com" <resin-interest@xxx.com>

> Date: Mon, 17 Oct 2005 15:22:33 -0400

> To: "resin-interest@xxx.com" <resin-interest@xxx.com>

> Conversation: 301 redirect

> Subject: 301 redirect

>

> Hi All,

>

> I am currently using resin 3.0.12 pro on Solaris 9. I am running resin

> with the built-in web server. My question is this: I need to rename some

> files and directories for SEO purposes and I am trying to determine the

> best way to do it. Our SEO company tells me the best way from a search

> engine perspective is to do a 301 redirect. I did some Googling and

> found the following page

> http://www.tamingthebeast.net/articles3/spiders-301-redirect.htm which

> explains how to do a 301 in an Apache .htaccess page. Since I am using

> the built-in web server is this possible or must I do this another way?

>

> The only other way I can think of to do this is to use the Rewrite

> Filter (I already have this configured in my web.xml file).

>

> <filter filter-name='rewrite'

> filter-class='com.caucho.filters.RewriteFilter'>

>     <init>

>         <rewrite pattern='/buyers/([A-Z]+)'

> target='/buy-a-business/$1'/>

>     </init>

> </filter>

>

> Example:

>

> /buyers/index.jsp  rewrites to /buy-a-business/index.jsp

>

> Does anyone know if the second option will have any ill effects or

> better yet how I can do a 301 redirect using resin's built in web

> server?

>

> Thomas

>

> --

>

> Thomas C. Moorer, Jr. ~ IT Manager

> 103 Church Street

> Mount Pleasant, SC 29464

> Sunbelt Business Advisors Network, LLC

> http://www.sunbeltnetwork.com

>

>

>

>

Received on Sat 22 Oct 2005 04:44:52 -0700

 · This message: [ Message body ]

 · Next message: Emmanuel Idi: "mod_caucho.so on Mac OS X Tiger..."

 · Previous message: Thomas Moorer: "Re: 301 redirect"

 · In reply to: Thomas Moorer: "Re: 301 redirect"

 · Contemporary messages sorted: [ By Date ] [ By Thread ] [ By Subject ] [ By

    Author ] [ By messages with attachments ]

This archive was generated by hypermail 2.1.8 : Thu Sep 28 2006 - 20:18:50 PDT