我收到以下错误:-
Syntax error on token "setRedirectStrategy", = expected after this token
这是什么意思?我该如何解决它。
<%@ page language="java" import="org.apache.http.client.methods.HttpUriRequest,org.apache.http.client.methods.HttpGet,org.apache.http.protocol.HttpContext,org.apache.http.impl.client.DefaultHttpClient,org.apache.http.HttpResponse,org.apache.http.HttpRequest,java.io.OutputStream,java.net.HttpURLConnection,java.net.URL,java.util.Collection,org.apache.commons.httpclient.Credentials,org.apache.commons.httpclient.auth.AuthenticationException,org.apache.commons.httpclient.auth.MalformedChallengeException,org.apache.commons.httpclient.params.DefaultHttpParams,org.apache.commons.httpclient.params.HttpParams,org.apache.commons.httpclient.auth.AuthScheme,org.apache.commons.httpclient.auth.AuthPolicy,org.apache.commons.httpclient.HttpClient,org.apache.commons.httpclient.UsernamePasswordCredentials,org.apache.commons.httpclient.auth.AuthScope,org.apache.commons.httpclient.methods.GetMethod,org.w3c.dom.*,javax.xml.parsers.DocumentBuilder,javax.xml.parsers.DocumentBuilderFactory,java.net.*,java.io.*" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%
String a_Url = request.getParameter( "url" ) ;
URL url = new URL (a_Url);
String encoding = new String(
org.apache.commons.codec.binary.Base64.encodeBase64
(org.apache.commons.codec.binary.StringUtils.getBytesUtf8("test:test"))
);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.setDoOutput(true);
connection.setRequestProperty ("Authorization", "Basic " + encoding);
InputStream content = (InputStream)connection.getInputStream();
BufferedReader in =
new BufferedReader (new InputStreamReader (content));
String line;
while ((line = in.readLine()) != null) {
out.println(line);
}
%>
<%!
HttpClient client = new HttpClient();
client.setRedirectStrategy(new DefaultRedirectStrategy() {
public boolean isRedirected(HttpRequest hr, HttpResponse hr1, HttpContext hc) {
if (hr1.getStatusLine().getStatusCode() == 302) {
return true;
}
return false;
}
public HttpUriRequest getRedirect(HttpRequest request, HttpResponse response, HttpContext context) {
HttpGet get = null;
try {
String newLocation = "" + response.getFirstHeader("Location");
newLocation = newLocation.substring(newLocation.indexOf("Location:")+10);
get = new HttpGet(newLocation);
} catch (Exception ex) {
System.out.println(ex.getLocalizedMessage());
}
return get;
}
});
%>