web.xml配置文件
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_9" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>stock_test</display-name>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_9" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>stock_test</display-name>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>
解决方案 »
- 有关Access数据库的请教
- FCKeditor怎样得到提交的文本内容,如果没用过那MyEclipse调试时怎么查看request的各个param的值
- JAVA里怎么调存储过程,怎么读存储过程的返回结果集?结果集里有BLOB字段怎么读出来?
- 问下eclipse的tomcat插件关于tomcat项目的目录结构问题
- struts中执行数据库操作大家是怎么做的?是直接把SQL语句放在action中?还是另外再做个类或者做个层?
- 请教JfreeChart横坐标标签过多显示不完整问题
- 关于数据实现分行
- 请告诉个方法,UP有分,解决奉送200分,有现成代码奉送400分。============================================>
- tomcat 与 Oracle连接
- 如何在jsp页面中调用一个jquery的分页组件?
- XML添加属性?求解答
- 关于ExtJS servlet问题,急急急!!!
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="stock_test" extends="struts-default">
<action name="stock" class="com.cn.Stock">
<result>/success.jsp</result>
</action>
</package>
</struts>
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;import com.opensymphony.xwork2.ActionSupport;public class Stock extends ActionSupport{
String name;
String stockId;
String dvalence;
String gdvalue;
String gdrange;
public void setName(String name) {
this.name = name;
} public void setStockId(String stockId) {
this.stockId = stockId;
} public void setDvalence(String dvalence) {
this.dvalence = dvalence;
} public void setGdvalue(String gdvalue) {
this.gdvalue = gdvalue;
} public void setGdrange(String gdrange) {
this.gdrange = gdrange;
} public String getGdrange() {
return gdrange;
} public String getGdvalue() {
return gdvalue;
} public String getDvalence() {
return dvalence;
} public String getStockId() {
return stockId;
} public String getName() {
return name;
} private static String getStaticPage(String surl) {
String htmlContent = "";
try {
java.io.InputStream inputStream;
java.net.URL url = new java.net.URL(surl);
java.net.HttpURLConnection connection = (java.net.HttpURLConnection) url
.openConnection();
connection.connect();
inputStream = connection.getInputStream();
byte[] bytes = new byte[1024 * 2000];
int index = 0;
int count = inputStream.read(bytes, index, 1024 * 2000);
while (count != -1) {
index += count;
count = inputStream.read(bytes, index, 1);
}
htmlContent = new String(bytes, "GB18030");
connection.disconnect();
} catch (Exception ex) {
ex.printStackTrace();
}
return htmlContent.trim();
}
public String execute() throws IOException {
String src = getStaticPage("http://hq.sinajs.cn/list=s_sh600058");
File file = new File("D:\\a.txt");
FileWriter resultFile = new FileWriter(file);
PrintWriter myFile = new PrintWriter(resultFile);// 写文件
myFile.println(src);
resultFile.close();
myFile.close();
FileReader fs = new FileReader(file);
BufferedReader in = new BufferedReader(fs);
String str = in.readLine();
String s[] = str.split("\"");
String strs[] = s[1].split(",");
String name = strs[0];//股票名称
String stockId = "600058";
String dvalence = strs[1]; //成交价
String gdvalue = strs[2]; //跌涨值
String gdrange = strs[3]; //跌涨幅
return SUCCESS;
}
}
pageEncoding="GB18030"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB18030">
<title>股票信息</title>
</head>
<body>
<table border="1">
<tr>
<td>ID</td>
<td>名字</td>
<td>成交价</td>
<td>涨跌值</td>
<td>涨跌幅</td>
<td>成交量</td>
<td>成交额</td>
</tr>
<tr>
<td><s:property value="stockId"/>
</td>
<td><s:property value="name"/>
</td>
<td><s:property value="dvalence"/>
</td>
<td><s:property value="gdvalue"/>
</td>
<td><s:property value="gdrange"/>
</td>
</tr>
</table>
</body></html>
这是新定义了一个变量,并不是你最上面定义的用来传递的变量。
应该写成
name = strs[0];//股票名称
下面的几个赋值语句也是如此。
String stockId = "600058";
String dvalence = strs[1]; //成交价
String gdvalue = strs[2]; //跌涨值
String gdrange = strs[3]; //跌涨幅这几个的赋值有问题,你是新定义的变量
去掉String应该就可以了
String stockId = "600058";
String dvalence = strs[1]; //成交价
String gdvalue = strs[2]; //跌涨值
String gdrange = strs[3]; //跌涨幅
这些在类里面定义了的,不需要再定义了,不然类里定义的属性不会被赋值
name = strs[0];//股票名称
stockId = "600058";
dvalence = strs[1]; //成交价
gdvalue = strs[2]; //跌涨值
gdrange = strs[3]; //跌涨幅
String stockId = "600058";
String dvalence = strs[1]; //成交价
String gdvalue = strs[2]; //跌涨值
String gdrange = strs[3]; //跌涨幅去String