『壹』 java怎麼獲得web應用的網址
比如這個路徑
http://localhost/servlet/DemoServlet?name=test
String scheme = request.getScheme();//獲取請求協議-http
int serverPort = request.getServerPort();//獲取服務埠號 -8080
String serverName = request.getServerName();//獲取服務域名(主機名) -localhost
String requestURI = request.getRequestURI();//獲取請求uri路徑 -/servlet/DemoServlet
String servletPath = request.getServletPath();//獲取servlet路徑 -/DemoServlet
String contextPath = request.getContextPath();//獲取上下文路徑 -/servlet
String queryString = request.getQueryString();//獲取uri請求參數 -/name=test
StringBuffer requestURL = request.getRequestURL();//獲取url路徑 -http://localhost/servlet/DemoServlet
『貳』 java開源web爬蟲哪個好用
1.nutch
地址:apache/nutch · GitHub
apache下的開源爬蟲程序,功能豐富,文檔完整。有數據抓取解析以及存儲的模塊。
2.Heritrix
地址:internetarchive/heritrix3 · GitHub
很早就有了,經歷過很多次更新,使用的人比較多,功能齊全,文檔完整,網上的資料也多。有自己的web管理控制台,包含了一個HTTP 伺服器。操作者可以通過選擇Crawler命令來操作控制台。
3.crawler4j
地址:yasserg/crawler4j · GitHub
因為只擁有爬蟲的核心功能,所以上手極為簡單,幾分鍾就可以寫一個多線程爬蟲程序。
當然,上面說的nutch有的功能比如數據存儲不代表Heritrix沒有,反之亦然。具體使用哪個合適還需要仔細閱讀文檔並配合實驗才能下結論啊~
還有比如JSpider,WebEater,Java Web Crawler,WebLech,Ex-Crawler,JoBo等等,這些沒用過,不知道。。。
『叄』 如何用javaweb實現,當點擊讀取按鈕時,獲取到輸入框的所輸入的網址,並將網頁顯示在讀取按鈕下面
不知道你是不是要這效果<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<head>
<metahttp-equiv="Content-Type"content="text/html;charset=utf-8"/>
<title>無標題文檔</title>
<script>
functionbtn(){
document.getElementById('myframe').src=document.getElementById('in').value;
document.getElementById('myframe').contentWindow.location.reload(true);
}
</script>
</head>
<bodystyle="text-align:center">
<divstyle="border:1pxsolidred;width:200px;height:200px;margin:0auto">
<p>URL:<inputid="in"/></p>
<buttonid="btn"style="width:75px"onclick="btn()">讀取</button>
</div>
<div>
<p>
<iframeid="myframe"width="800"height="500"src="http://www..com"></iframe>
</p>
</div>
</body>
</html>
『肆』 在java中怎麼獲取頁面的路徑
第一種:
File f = new File(this.getClass().getResource("/").getPath());
System.out.println(f);
結果:
C:Documents%20and%
獲取當前類的所在工程路徑;
如果不加「/」
File f = new File(this.getClass().getResource("").getPath());
System.out.println(f);
結果:
C:Documents%20and%comtest
獲取當前類的絕對路徑;
第二種:
File directory = new File("");//參數為空
String courseFile = directory.getCanonicalPath() ;
System.out.println(courseFile);
結果:
C:Documents and
獲取當前類的所在工程路徑;
第三種:
URL xmlpath = this.getClass().getClassLoader().getResource("selected.txt");
System.out.println(xmlpath);
結果:
file:/C:/Documents%20and%
20Settings/Administrator/workspace/projectName/bin/selected.txt
獲取當前工程src目錄下selected.txt文件的路徑
第四種:
System.out.println(System.getProperty("user.dir"));
結果:
C:Documents and
獲取當前工程路徑
第五種:
System.out.println( System.getProperty("java.class.path"));
結果:
C:Documents and bin