package hr;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
public class GuPiao {
public String getGupiao(String gp){
String u="http://quote.eastmoney.com/sh"+gp+".html";
URL url;
try {
url = new URL(u);
URLConnection conn= url.openConnection();//按了回车
InputStream is=conn.getInputStream();
//加入了缓存流
BufferedReader br=new BufferedReader(
new InputStreamReader(is));
String content="";
content= br.readLine();
String temp="";
while((temp=br.readLine())!=null){
content+=temp;
}
br.close();
is.close();
return content;
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}//地址栏
return null;
}
}
<%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<script type="text/javascript" src="dwr/engine.js"></script>
<script type="text/javascript" src="dwr/util.js"></script>
<script type="text/javascript" src="dwr/interface/myjs.js"></script>
<script type="text/javascript">
function getGp(){
myjs.getGupiao($("gp").value,function(date){
document.getElementById("div").innerHTML=date;
});
}
</script>
</head>
<body>
<input type="text" id="gp" onblur="getGp()">
<div id="div" > </div>
</body>
</html>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dwr PUBLIC
"-//GetAhead Limited//DTD Direct Web Remoting 2.0//EN"
"http://getahead.ltd.uk/dwr/dwr20.dtd">
<dwr>
<allow>
<create javascript="myjs" creator="new">
<param name="class" value="hr.GuPiao"></param>
</create>
</allow>
</dwr>
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<servlet>
<servlet-name>dwr</servlet-name>
<servlet-class>org.directwebremoting.servlet.DwrServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>dwr</servlet-name>
<url-pattern>/dwr/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<login-config>
<auth-method>BASIC</auth-method>
</login-config>
</web-app>