2012-07-19 89 views
0

我有一個被稱爲重定向到jsp的(struts 2)動作。我試圖用HttpClient把這個jsp保存到html。除了一件事情之外,這可以很好地工作,服務器追加jsessionid=RandomText任何其他操作出現在html中的任何地方。如何從html中刪除jsessionid(從jsp轉換而來)

如何從最終的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); 

回答

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

這兩個環節是有很大的幫助:

+0

我可以知道我應該在哪裏得到這段代碼嗎? – J888 2013-10-15 00:43:01

0

使用的Java RegularExpression和內容替換jsessionid=<ID> up to ?

+0

相反,我可以指定請求或客戶端中的東西?另外,你能幫我表達一下嗎? – brainydexter 2012-07-19 10:50:43

相關問題