我的food类
public class Food implements java.io.Serializable { // Fields private Integer foodid;
private String etid;
private String fdname;
private Double fdprice;
private String kind; // Constructors /** default constructor */
public Food() {
} /** full constructor */
public Food(String etid, String fdname, Double fdprice, String kind) {
this.etid = etid;
this.fdname = fdname;
this.fdprice = fdprice;
this.kind = kind;
} // Property accessors public Integer getFoodid() {
return this.foodid;
} public void setFoodid(Integer foodid) {
this.foodid = foodid;
} public String getMarketid() {
return this.etid;
} public void setMarketid(String etid) {
this.etid = etid;
} public String getFdname() {
return this.fdname;
} public void setFdname(String fdname) {
this.fdname = fdname;
} public Double getFdprice() {
return this.fdprice;
} public void setFdprice(Double fdprice) {
this.fdprice = fdprice;
} public String getKind() {
return this.kind;
} public void setKind(String kind) {
this.kind = kind;
}}
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
我的action
public class searchfirst extends ActionSupport{
private FoodDAO foodDAO = new FoodDAO();
private List<Food> searchfirstL = new ArrayList(); private List<Food> getSearchfirstL(){
return searchfirstL;
}
private void setSearchfirstL(List<Food> searchfirstL){
this.searchfirstL = searchfirstL;
}
public String execute()throws Exception{
this.setSearchfirstL(foodDAO.findAll());
System.out.println(searchfirstL.size());
System.out.println(((Food)(searchfirstL.get(0))).getFoodid());
//HttpServletRequest request = ServletActionContext.getRequest();
//request.setAttribute("searchfirstL",this.getSearchfirstL());
return "showfirstsearch";
}
}
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
我的jsp
<s:iterator value="searchfirstL" status="status">
<tr>
<td height="25">
<div align="center">
<s:property value="foodid"/>
</div>
</td>
<td height="25">
<div align="center">
<s:property value="etid"/>
</div>
</td>
<td height="25">
<div align="center">
<s:property value="fdname"/>
</div>
</td>
<td height="25">
<div align="center">
<s:property value="fdprice"/>
</div>
</td>
<td height="25">
<div align="center">
</div>
<br></td></tr> </s:iterator>
public class Food implements java.io.Serializable { // Fields private Integer foodid;
private String etid;
private String fdname;
private Double fdprice;
private String kind; // Constructors /** default constructor */
public Food() {
} /** full constructor */
public Food(String etid, String fdname, Double fdprice, String kind) {
this.etid = etid;
this.fdname = fdname;
this.fdprice = fdprice;
this.kind = kind;
} // Property accessors public Integer getFoodid() {
return this.foodid;
} public void setFoodid(Integer foodid) {
this.foodid = foodid;
} public String getMarketid() {
return this.etid;
} public void setMarketid(String etid) {
this.etid = etid;
} public String getFdname() {
return this.fdname;
} public void setFdname(String fdname) {
this.fdname = fdname;
} public Double getFdprice() {
return this.fdprice;
} public void setFdprice(Double fdprice) {
this.fdprice = fdprice;
} public String getKind() {
return this.kind;
} public void setKind(String kind) {
this.kind = kind;
}}
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
我的action
public class searchfirst extends ActionSupport{
private FoodDAO foodDAO = new FoodDAO();
private List<Food> searchfirstL = new ArrayList(); private List<Food> getSearchfirstL(){
return searchfirstL;
}
private void setSearchfirstL(List<Food> searchfirstL){
this.searchfirstL = searchfirstL;
}
public String execute()throws Exception{
this.setSearchfirstL(foodDAO.findAll());
System.out.println(searchfirstL.size());
System.out.println(((Food)(searchfirstL.get(0))).getFoodid());
//HttpServletRequest request = ServletActionContext.getRequest();
//request.setAttribute("searchfirstL",this.getSearchfirstL());
return "showfirstsearch";
}
}
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
我的jsp
<s:iterator value="searchfirstL" status="status">
<tr>
<td height="25">
<div align="center">
<s:property value="foodid"/>
</div>
</td>
<td height="25">
<div align="center">
<s:property value="etid"/>
</div>
</td>
<td height="25">
<div align="center">
<s:property value="fdname"/>
</div>
</td>
<td height="25">
<div align="center">
<s:property value="fdprice"/>
</div>
</td>
<td height="25">
<div align="center">
</div>
<br></td></tr> </s:iterator>
解决方案 »
- 没有用sping的项目用spring-security作权限合适吗?两者什么关系?
- 关于jquery方法trigger( event, [data] )和triggerHandler( event, [data] )
- 虚心求教!!!
- 求教,为什么已经产生.class文件,不能运行,我安了JDK,我是初学者
- 怎么部署web程序
- 实体bean的关联
- 解决后马上结:怎么总是得到一条记录??
- 如何用java實現將一個文件拷貝到另外一個指定的地方呢﹖謝謝﹗
- 关于使用javamail接收notes油箱邮件的问题??急!!!
- 一个关于导致cpu100%问题
- 高分求 JAVA 彩信在线编辑器开发想关资料
- jq如何调用js里面的变量呢
<s:property value="foodid"/> 改成 <s:property value="food.foodid"/>
<s:property value="etid"/> 改成 <s:property value="food.etid"/>
其它也一样这样改试试行不行
<s:iterator id="search" value="#request.searchfirstL" status="status">
<tr>
<td height="25">
<div align="center">
<s:property value="${search.foodid}"/>
</div>
</td> <td height="25">
<div align="center">
<s:property value="${search.etid}"/>
</div>
</td> <td height="25">
<div align="center">
<s:property value="${search.fdname}"/>
</div>
</td>
<td height="25">
<div align="center">
<s:property value="${search.fdprice}"/>
</div>
</td>
<td height="25">
<div align="center">
</div>
<br></td></tr> </s:iterator>貌似没有错啊 你用迭代的时候id很重要,因为每次迭代的时候Struts每一项都会存储到StackContext的范围中 你在试试 我下午有课 问题请留言 我想应该是没有问题的 我想有心提示 我一般用C标签 Struts2的标签都不是很稳定
${}这个好像不能用严重: Servlet.service() for servlet jsp threw exception
org.apache.jasper.JasperException: /searchfirst.jsp(236,6) According to TLD or attribute directive in tag file, attribute value does not accept any expressions
你是不是想点开一个页面的时候,就自动从数据拿出数据,然后填充到jsp页面?如果是的话,好办了。
第一:设置你的访问路径,比如你的jsp页面名字是food.jsp。如果你访问这个页面用这个url:http://localhost:8080/工程名/food.jsp那么这样就错了。url应该是这样的:http://localhost:8080/工程名/namespace!searchfood.action这样就能访问searchfood这个action了。然后在struts.xml里面配置好。让这个action的返回结果到food.jsp。food.jsp可以使用这个action里头searchfirstL属性来填充了。
还有什么不懂?
我是有一个按钮做表单提交,提交的时候运行action,然会有searchfirstL的List,然后再从struts中跳转到searchfirst。jsp,这样来显示的。。应该也可以吧?
目标:我想要一个页面在加载的时候同时查询数据库中的数据,然后显示出来
遇到的问题:jsp显示不出来啊
lz的这条语句在后台有打印出来foodid吗?如果没有就是数据库查询的问题。
应该有个var属性吧<s:iterator value="searchfirstL" status="status" var="food">
< tr>
<td height="25">
<div align="center">
<s:property value="#food.foodid"/>
</div>
</td>
</s:iterator>最好先 <s:property value=“searchfirstL"/>看list是否有值,如果没有后台this.setSearchfirstL(foodDAO.findAll());
改成searchfirstL = foodDAO.findAll();
<filter-mapping>
<filter-name>struts2</filter-name>
<!--url-pattern默认为*.action,必须改为/*否则无法支持struts2标签--> <url-pattern>/*</url-pattern>
</filter-mapping>
如果lz的项目中struts标签是可用的,那么就是你页面上的<s:iterator>标签的问题了,lz可以给<s:iterator>标签指定一个Id属性值,先输出一个属性的值试一下
显示直接这样写就可以了<s:property value="#search.etid"/>
好像吧#search.省略也可以,试一下
我想说
我的List里面是有东西的,我有输出语句的,请看action中,在MyEclipse后台控制中有结果输出
我先试试各位的方法
标签是可用的
<s:iterator>id也加过了,还是不行
var这个我改改看,有后台的,List里是有数据的
而且这是struts1还是2 啊..
我用的是Struts2
回复35楼:
那个var的方法还是不可以