首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

struts1.2的action方法运行没有结果!另求(配置连接池)

2011-12-10 
求助:struts1.2的action方法运行没有结果!另求(配置连接池)RT,同一个action类里其他的方法都可以,唯独这一

求助:struts1.2的action方法运行没有结果!另求(配置连接池)
RT,同一个action类里其他的方法都可以,唯独这一个运行页面没有结果,程序不报错,不知道哪里没写对,求指导。
代码:

Java code
public ActionForward showall(ActionMapping mapping, ActionForm form,            HttpServletRequest request, HttpServletResponse response)    {        NewsForm AllNewsActionForm=(NewsForm)form;        try        {            ActionNews actionNews = new ActionNews(AllNewsActionForm);            List<String[]>result=actionNews.search();            if(result.size()>0)            {                request.setAttribute("result",result);                request.setAttribute("info_all", "总记录数:" + String.valueOf(result.size()));            }            else                  request.setAttribute("info_all", "没有符合要求的记录!");            }        catch(Exception e)        {            request.setAttribute("info_all",e.getMessage());                    }        return mapping.findForward("searchAll");    }


具体操作方法代码:

Java code
public List<String[]>search() throws Exception {     List<String[]> result = new LinkedList<String[]>();     String sql="select * from s_news";     PreparedStatement pstmt= conn.prepareStatement(sql);     ResultSet rs =pstmt.executeQuery();     while(rs.next())     {         String[] row=new String[6];           row[0] = rs.getString(1);           row[1] = rs.getString(2);           row[2] = rs.getString(3);           row[3] = rs.getString(4);           row[4] = rs.getString(5);           row[5] = rs.getString(6);           result.add(row);     }     rs.close();     conn.close();     return result; }


jsp:
HTML code
<c:set var="result" value="${requestScope.result}" />       <table width="100%">            <tr align="center">                <td>                     ${requestScope.info_all}                </td>            </tr>            <tr align="center">                <td>                <logic:present name="result">                 <table border="1">                              <tr align="center">           <td> 编号 <input type="hidden" name="news_detail" value="${row[4]}"></td>                                  <td> 主题 </td>                                  <td> 作者</td>                                  <td> 日期</td>                                  <td align="center" colspan=4>操作</td>                              </tr>                <logic:iterate id="row" name="result">                          <tr align="center">                    <td> ${row[0]} </td>                    <td> ${row[1]} </td>                     <td> ${row[2]} </td>                    <td> ${row[3]}</td>                                                                  </tr>                              </logic:iterate>                              </table>                              </logic:present>                              </td>                                                      </tr>        </table>


xml:

Java code
<forward name="updateNews" path="/message.jsp"/>   <forward name="AllNewsAction" path="/index.jsp"/>  </global-forwards>  <action-mappings>  <action name="AllNewsActionForm" path="/AllNewsAction" scope="request" type="action.AllNewsAction" parameter="method">  <forward name="save" path="/message.jsp" />  <forward name="searchAll" path="/index.jsp" />  <forward name="search" path="/index.jsp" />  <forward name="update" path="/message.jsp" />  </action>  </action-mappings> 



附:

另求如何在struts-config.xml里配置连接池,如何调用,我用的是struts1.2能结合我这个例子写一下最好了。。感谢。

[解决办法]
页面取值取错了?
[解决办法]
给你个配置连接池的吧,用dbcp或者c3p0都行,网上搜都能收到,下边是dbcp的struts1.2的数据库连接池配置写法
在Struts中配置和使用DBCP连接池
1).下载并部署DBCP安装包和MySQL驱动包:
commons-dbcp-1.2.1.jar;commons-pool-1.2.jar;mysql-connector-java-5.0.8-bin.jar
2).在struts-config.xml中配置DBCP数据源:
要让Struts集成DBCP,就必须在struts-config.xml配置一个<data-source>组件,配置DBCP的相关属性.
type:表示DBCP连接池的类org.apache.commons.dbcp.BasicDataSource;
driverClassName:连接MySQL的驱动类com.mysql.jdbc.Driver;
url:连接到JDBC的URL,不同的数据库其值也不同,MySQL为jdbc:mysql://localhost:3306/dbname;
username:用户名称;
password:用户密码;
maxActive:最大数据库连接数,0为没有限制;
maxWait:最大等待秒数,单位为ms,超过时间会丢出错误信息;
可选属性:
defaultAutoCommit:对于事务是否autoCommit,默认值为true;
defaultReadOnly:对于数据库是否只能读取,默认值为false;
validationQuery:验证连接是否成功,SQL SELECT指令至少要返回一行.
配置后的结果如下:
<data-sources>
<data-source type="org.apache.commons.dbcp.BasicDataSource">
<set-property property="driverClassName" value="com.mysql.jdbc.Driver" />
<set-property property="url" value="jdbc:mysql://localhost:3306/dbname" />
<set-property property="username" value="root" />
<set-property property="password" value="xxx" />
<set-property property="maxActive" value="10" />
<set-property property="maxWait" value="5000" />
<set-property property="defaultAutoCommit" value="false" />
<set-property property="defaultReadOnly" value="false" />
<set-property property="validationQuery" value="SELECT COUNT(*) FROM user" />
</data-source>
</data-sources>
在Action中取得DBCP数据源:
在struts的Action基类中提供了一个方法,传递一个request对象就可以取得该连接池的数据源对象,如下所示:
DataSource ds=getDataSource(request);
通过DataSource的getConnection方法就可以取得数据库连接对象:
Connection conn=ds.getConnection();
 
[解决办法]
帮顶。
[解决办法]
顶吧。
[解决办法]
看了一遍 没理解 你问题出在哪里啊~~
是页面掉不到类里的方法 还是 类里传回去页面收不到?
[解决办法]
打断点 看看 最后要往页面传得 容器或者对象里面 是否有值,如果有值 再看看页面取值的对象或者属性是否正确, 一点点 跟着 走..
[解决办法]
呵呵, 既然代码没有问题 你看看你的配置是不是有问题 项目跑起来打断点 一步一步看那里有错误

热点排行