0

I have a (struts 2) action which on being called redirects to a jsp. I'm trying to save this jsp to html using HttpClient. This works fine apart from one thing, server appends jsessionid=RandomText wherever another action is present in the html.

How can I remove jsessionid from the final html ?

Sample from rendered html:

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

This is how I am saving the jsp to 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);
brainydexter
  • 19,826
  • 28
  • 77
  • 115

2 Answers2

1

Following amicngh's suggestion, the regex did the trick! I was hoping I could specify something in the client/request, but oh well.

For anyone else, this is what did it:

    // 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);

These two links were of great help:

brainydexter
  • 19,826
  • 28
  • 77
  • 115
0

Use Java RegularExpression and replace jsessionid=<ID> up to ? from content.

amicngh
  • 7,831
  • 3
  • 35
  • 54