『壹』 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