0

呼び出されると jsp にリダイレクトする (struts 2) アクションがあります。HttpClient を使用して、この jsp を html に保存しようとしています。jsessionid=RandomTextこれは、html に別のアクションが存在する場合にサーバーが追加するという 1 つのことを除けば、問題なく機能します。

最終的な html から jsessionid を削除するにはどうすればよいですか?

レンダリングされた html のサンプル:

<a href='/wah/destinationSEO.action;jsessionid=123ASDGA123?idDestination=22'>

これは、jsp を html に保存する方法です。

DefaultHttpClient httpClient = new DefaultHttpClient();
HttpGet getRequest = new HttpGet("http://127.0.0.1:8080/wah/destinationSEO.action?idDestination=8");

HttpResponse response = httpClient.execute(getRequest);

if (response.getStatusLine().getStatusCode() != 200) {
    throw new RuntimeException("Failed : HTTP error code : "
            + response.getStatusLine().getStatusCode());
}
httpClient.getConnectionManager().shutdown();

String content = CharStreams.toString(new InputStreamReader(response.getEntity().getContent()));

String path="D:/wahSVN/trunk/src/main/webapp/seo.html";
File html = new File(path);
html.createNewFile();
Files.append(content, html, Charsets.UTF_8);
4

2 に答える 2

1

amicngh の提案に従って、正規表現がうまくいきました。クライアント/リクエストで何かを指定できることを望んでいましたが、まあまあです。

他の人にとっては、これがそれをしたことです:

    // code as written above
    Pattern pattern = Pattern.compile(";jsessionid(=\\w+)");
    Matcher m = pattern.matcher(content);

    content = m.replaceAll("");

    Files.write(content, html, Charsets.UTF_8);

次の 2 つのリンクは非常に役立ちました。

于 2012-07-19T11:57:51.427 に答える
0

Java正規表現を使用し、コンテンツから置き換えjsessionid=<ID> up to ?ます。

于 2012-07-19T10:48:51.497 に答える