网站jsp页面中有一个<a href="news.jsp">跳转到新闻页面!</a>
在news.jsp中我需要从数据库得到新闻标题,这个步骤我想在action页面下实现查找,传值,于是我写了<a href="news.jsp" action="news" method="post">跳转到新闻页面</a>在struts.xml中如下
<action name="index" class="com.edu.ytu.MessageAnnounceAction">MessageAnnounceAction.java中我进行了数据的查找和传值。现在的问题是我点击链接的话,页面直接跳转到news.jsp页面,并没有去查找执行MessageAnnounceAction中的操作。求高手指教如何在跳转的同时,进行action的操作,是不是我的<a href="news.jsp" action="news" method="post">跳转到新闻页面</a>语句错误?应该如何去写??

解决方案 »

  1.   

    <s:a href="index.action">
    <action name="index" class="com.edu.ytu.MessageAnnounceAction"> 
             <result name="你action return 的">/路径/new.jsp
      

  2.   

    <action name="saveStudent" class="org.pany.struts2.action.StudentAction">
    <result name="suc" type="redirect">/findStu.action</result>
    </action>
    要配置 result的type
      

  3.   

    我已经写了跳转语句<action name="index" class="com.edu.ytu.MessageAnnounceAction">
                <result name="news">
                /news.jsp    
                </result>MessageAnnounceAction中
                       db2 = new Db2();
    if(1==1){  //测试,数据库是能够连接上的

    db2.dbConnect();
    String sqlStr = "select * from db2admin.news where id='1'";
    db2.setSqlStr(sqlStr);
    rst = db2.executeQuery(sqlStr);
    String a = rst.getString(2);
    System.out.println(a);

    rst.close();
    db2.dbClose();
    return "news";
    在jsp页面加上<s:a href="index.action">后不能跳转了,提示Unknown tag(s:a),我又在jsp页面头加上了
    <%@ taglib prefix="s" uri="/struts-tags" %>
    ,依然报一样的错:
    type Exception reportmessage description The server encountered an internal error () that prevented it from fulfilling this request.

    exception 
    org.apache.jasper.JasperException: /index.jsp(36,0) Unterminated &lt;s:a tag求怎样解决
      

  4.   

    是你的"<s:a" 看看是"<"这个是不是中文的<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
        <base href="<%=basePath%>">
        
        <title>My JSP 'list.jsp' starting page</title>
        
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">    
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->  </head>
      
      <body>
      <s:form action="" method="post">
    <s:iterator value="resultList" status="index" id="l">
    <s:if test="${id == '18'}">
    test Success
    </s:if>
    <s:if test="#index.odd == true">
    <tr style="background-color:#FFFF00">
    </s:if>
    <s:else>
    <tr>
    </s:else>
    <td>用户名</td>
    <td>
    <s:property value="username"/>
    <s:property  value="love"/>
    <s:property value="lastmodifytime"/>
    <a href="delete.action?id=<s:property id="l" value="id"/>">
    删除
    </a>

    <a href="edit.action?id=<s:property id="l" value="id"/>">
    编辑
    </a>
    </td>
    </s:iterator>
    </s:form>
      </body>
    </html>