Servlet

 

頁面避免暫存

response.addHeader("Pragma", "No-cache");
response.addHeader("Cache-Control", "no-cache");
response.addDateHeader("Expires", 1);
 
利用 java parse 網頁字串
 
URL url = null;
 
try {
 
url = new URL( address );
 
HttpURLConnection uc = (HttpURLConnection) url.openConnection();
 
/**
* 因為在 tomcat 6 上是設定 big5
* 所以在此行需設定 utf-8 編碼
* 否則收到的內容會是亂碼
* 造成無法解析
*/
BufferedReader in = new BufferedReader(new InputStreamReader(uc.getInputStream(), "UTF-8" )  );
 
String line = "";
 
while( ( line = in.readLine() ) != null  ) {
 
if( line.contains( counterWording ) ) {
 
//System.out.println("line: " + line );
 
savePersonCounter(line );
}
}
 
in.close();
 
}
catch(MalformedURLException e ) {
 
System.out.println("連線失敗: " + e.toString() );
 
e.printStackTrace();
}
catch(IOException e ) {
 
System.out.println("WorkflowPersonCounter 執行失敗" );
e.printStackTrace();
}
 
 
URL url = null;
 
try {
 
url = new URL( address );
 
HttpURLConnection uc = (HttpURLConnection) url.openConnection();
 
/**
* 因為在 tomcat 6 上是設定 big5
* 所以在此行需設定 utf-8 編碼
* 否則收到的內容會是亂碼
* 造成無法解析
*/
BufferedReader in = new BufferedReader(new InputStreamReader(uc.getInputStream(), "UTF-8" )  );
 
String line = "";
 
while( ( line = in.readLine() ) != null  ) {
 
if( line.contains( counterWording ) ) {
 
//System.out.println("line: " + line );
 
savePersonCounter(line );
}
}
 
in.close()

 

© 2015 版權所有。

Create a website for freeWebnode