weixin_42446630
weixin_42446630
2011-04-23 18:32

Strut2连接数据库无法显示数据到页面的问题

已采纳


最近在做毕设,Struts2是现学现卖的,不是很会。遇见个小问题:就是从数据库中获取数据无法显示到jsp页面问题。应该是View层有些小问题,请经验丰富的老手高手和新手们帮忙看一下。感激万分。以下是代码: 

index.jsp 

用于显示的Struts标签: 
<s:iterator   value= "newinv "> 
    <tr>   
            <td> 
<a   href= "view_inv.jsp "> mmmm <s:property   value= "post "   /> </a> 
            </td> 
            <td> <s:property   value= "pnum "   /> </td> 
            <td> <s:property   value= "ename "   /> </td> 
            <td> <s:property   value= "pdate "   /> </td> 
    </tr> 
</s:iterator> 
—————————————————————————————————————————————————— 
MainAction.java代码: 

public class MainAction extends ActionSupport {

/**
*  
*/
private static final long serialVersionUID = 1L;
//最新求职
private List<App_Stu> newapp=new ArrayList<App_Stu>();
//最新招聘
private List<Enterprise> newinv=new ArrayList<Enterprise>();
@Override
public String execute() throws Exception {
EntSerImp ent_ser= new EntSerImp();

StuSerImp stu_ser=new StuSerImp();
this.newinv=stu_ser.viewNewAPP();
this.newapp=ent_ser.viewNewAPP();
return SUCCESS;
}



public List<App_Stu> getNewapp() {
return newapp;
}


public List<Enterprise> getNewinv() {
return newinv;
}



public void setNewapp(List<App_Stu> newapp) {
this.newapp = newapp;
}



public void setNewinv(List<Enterprise> newinv) {
this.newinv = newinv;
}

}
—————————————————————————————————————————————— 
StuSerImp.java   中的方法 
public   class   StuSerImp   implements   EntSer   { 

public   List <Enterprise>   viewNewAPP()   { 
StuDaoImp   dao=new   StuDaoImp(); 
try   { 
return   dao.viewNewINV(); 
}   catch   (SQLException   e)   { 
//   TODO   Auto-generated   catch   block 
e.printStackTrace(); 

return   null; 
}} 
—————————————————————————————————————————————— 
StuDaoImp.java中的方法 
public   class   StuDaoImp   implements   StuDao   { 

public   void   logout(String   sno)   throws   SQLException   { 
//   TODO   Auto-generated   method   stub 




public   List <Enterprise>   viewNewINV()   throws   SQLException   { 
List <Enterprise>   apps=new   ArrayList <Enterprise> (); 
Connection   conn=DateBaseConnection.getConnection(); 
Statement   stmt=conn.createStatement(); 
ResultSet   result=stmt.executeQuery( "select   post,pnum,ename,pdate   from     "   + 
"ent   e,pap   p   where   e.eno=p.eno   order   by   pdate "); 
while(result.next()){ 
String   post=result.getString( "post "); 
int   num=result.getInt( "pnum "); 
String   ena=result.getString( "ename "); 
Date   date=result.getDate( "pdate "); 

Enterprise   app=new   Enterprise(); 
app.setPost(post); 
app.setPnum(num); 
app.setEname(ena); 
app.setPdate(date); 
apps.add(app); 
return   apps; 

conn.close(); 
return   null; 

}


———————————————————————————————————————————————————— 
Enterprise的Model类: 
public   class   Enterprise   { 

//   -------------------企业基本信息----------------// 
//   上市编号 
private   String   eno; 
//   企业名称 
private   String   ename; 
//   企业简介 
private   String   entsyn; 
//   企业网址 
private   String   enet; 
//   所在地 
private   String   eadress; 
//   登录密码 
private   String   epwd; 
//   用户类型 
private   int   usertype; 
//   ---------------------企业招聘信息--------------------// 
//   招聘职位 
private   String   post; 
//   招聘人数 
private   int   pnum; 
//   工作责任 
private   String   wrpsb; 
//   职能要求 
private   String   funab; 
//   联系人 
private   String   linkman; 
//   电话 
private   String   tel; 
//   电子邮箱 
private   String   email; 
//   工作地点 
private   String   wadr; 
//   发布时间 
private   Date   pdate; 

public   String   getEno()   { 
return   eno; 


public   void   setEno(String   eno)   { 
this.eno   =   eno; 


public   String   getEname()   { 
return   ename; 


public   void   setEname(String   ename)   { 
this.ename   =   ename; 


public   String   getEntsyn()   { 
return   entsyn; 


public   void   setEntsyn(String   entsyn)   { 
this.entsyn   =   entsyn; 


public   String   getEnet()   { 
return   enet; 


public   void   setEnet(String   enet)   { 
this.enet   =   enet; 


public   String   getEadress()   { 
return   eadress; 


public   void   setEadress(String   eadress)   { 
this.eadress   =   eadress; 


public   String   getEpwd()   { 
return   epwd; 


public   void   setEpwd(String   epwd)   { 
this.epwd   =   epwd; 


public   int   getUsertype()   { 
return   usertype; 


public   void   setUsertype(int   usertype)   { 
this.usertype   =   usertype; 


public   String   getPost()   { 
return   post; 


public   void   setPost(String   post)   { 
this.post   =   post; 


public   int   getPnum()   { 
return   pnum; 


public   void   setPnum(int   pnum)   { 
this.pnum   =   pnum; 


public   String   getWrpsb()   { 
return   wrpsb; 


public   void   setWrpsb(String   wrpsb)   { 
this.wrpsb   =   wrpsb; 


public   String   getFunab()   { 
return   funab; 


public   void   setFunab(String   funab)   { 
this.funab   =   funab; 


public   String   getLinkman()   { 
return   linkman; 


public   void   setLinkman(String   linkman)   { 
this.linkman   =   linkman; 


public   String   getTel()   { 
return   tel; 


public   void   setTel(String   tel)   { 
this.tel   =   tel; 


public   String   getEmail()   { 
return   email; 


public   void   setEmail(String   email)   { 
this.email   =   email; 


public   String   getWadr()   { 
return   wadr; 


public   void   setWadr(String   wadr)   { 
this.wadr   =   wadr; 


public   Date   getPdate()   { 
return   pdate; 


public   void   setPdate(Date   pdate)   { 
this.pdate   =   pdate; 










 

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • xiaowen0713 xiaowen0713 10年前

    index.jsp

    用于显示的Struts标签:




    mmmm





    /s:iterator

    这样试试,struts标签使用的是OGNL表达式,以#开头吧?

    点赞 评论 复制链接分享

相关推荐