我想做个主页index.jsp,在这个页面中根据请求参数include不同的jsp或action。目前只能用<s:action>包含一个action到index.jsp中,但是action名称必须是静态的,想运行动态action怎么办?<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %> 
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Exam Center</title>
<link href="default.css" rel="stylesheet" type="text/css" media="screen" />
</head>
<body>
<!-- start header -->
<div id="header">
<div id="logo">
<h1>题库中心</h1>
<p>By Free CSS Templates</p>
</div>
<div id="loginform">
<form method="post" action="">
<fieldset id="test">
<input id="s" type="text" name="name" value="" />
<input id="s" type="password" name="password" value="" />
<input id="x" type="submit" value="登录" />
</fieldset>
</form>
</div>
</div>
<!-- end header --><% 
String[] pageTitle={
"试题管理",
"试卷管理",
"知识点管理"};String[][] contentTitle={
{"试题录入","试题查询与维护","试题统计"},
{"试卷查询","组卷"},
{"知识点查询","知识点维护"}
};
String[][] contentUrl={
{"QuestionInfo.action","question_query.jsp","question_statistics.jsp"},
{"",""},
{"",""}
};
int pageId,contentId;
if(request.getParameter("pageId")==null)
pageId=0;
else
pageId=Integer.parseInt(request.getParameter("pageId"));
if(request.getParameter("contentId")==null)
contentId=0;
else
contentId=Integer.parseInt(request.getParameter("contentId"));
%><!-- start menu -->
<div id="menu">
<ul>
<%for(int i=0;i<pageTitle.length;i++){
if(i==pageId)
out.println("<li class='current_page_item'><a href='index.jsp?pageId="+i+"'>"+pageTitle[i]+"</a></li>");
else
out.println("<li><a href='index.jsp?pageId="+i+"'>"+pageTitle[i]+"</a></li>");
}
%>
</ul>
</div>
<!-- end menu --><!-- start page -->
<div id="page">
<!--下面的内容出错,显示According to TLD or attribute directive in tag file, attribute name does not accept any expressions -->

<s:action name="${contentUrl[pageId][contentId]}" executeResult="true"/>
<!-- start sidebar -->
<div id="sidebar">
<ul>
<li>
<h2><%=pageTitle[pageId]%></h2>
<ul>
<%
for(int i=0;i<contentTitle[pageId].length;i++)
out.println("<li><a href='index.jsp?pageId="+pageId+"&contentId="+i+"'>"+contentTitle[pageId][i]+"</a></li>");
 %>
</ul>
</li>
</ul>
</div>
<!-- end sidebar -->
<div style="clear: both;">&nbsp;</div>
</div>
<!-- end page -->
<div id="footer">
<p>&copy;2010 All Rights Reserved. &nbsp;&bull;&nbsp; Design by <a href="http://www.freecsstemplates.org/">Free CSS Templates</a> &nbsp;&bull;&nbsp; Icons by <a href="http://www.famfamfam.com/">FAMFAMFAM</a>.</p>
</div>
</body>
</html>

解决方案 »

  1.   

    看看...
    <s:action name="%{contentUrl[pageId][contentId]}" executeResult="true"/>
      

  2.   

    还是不行,好像是对url的解析出错,提示:
    严重: Could not execute action: /
    There is no Action mapped for action name . - [unknown location]
      

  3.   

    <s:url id="idUrlAction" value="%{contentUrl[pageId][contentId]}" />
    <s:action name="%{idUrlAction}" executeResult="true"/>
      

  4.   

    思路和上面一样,结果也差不多
    严重: Could not execute action: /?pageId=0
      

  5.   

    String[][] contentUrl={
    {"QuestionInfo","question_query.jsp","question_statistics.jsp"},
    {"",""},
    {"",""}
    };在用
    <s:action name="%{contentUrl[pageId][contentId]}" executeResult="true"/>
      

  6.   

    我在我的项目中调试OK1.jsp:
    <s:iterator value="strs" status="ss" id="v">
    <s:property value="v"/>
    <s:action name="%{v}" executeResult="true"></s:action>
    </s:iterator>2.action:
    private String[] strs;/**
     * ロードメソッド
     * 
     * @return
     * @throws Exception
     */
    public String doLoad() throws Exception { // 初期化
    strs = new String[] { "SJA010Url1", "SJA010Url2" }; return SUCCESS;
    }
      

  7.   

    已经解决了,7楼是正解。只能用<s:action>,struts标签库对url自动加.action,所以必须写成name="QuetionInfo",和<s:form action="QuestionInfo">相同。
      

  8.   

    用js不行么
    <form="a" action="" xxx></form>
    <js...>
    function xx(){
    var form = document.forms[0];//根据实际情况
    form.action="xxxx"
    form.submit();
    }
    我觉得再多2个action也无所谓
      

  9.   

    我把问题总结一下:
    1、首先在主页index.jsp中把所有链接都设置成index.jsp的重新访问,这样所有功能部分都在主页中的content部分显示。
    2、为了实现1,把链接地址设置成变量,并通过index的pageId和contentId动态调整内容
    3、jsp:include无法处理action,所以只能用s:action,但是s:action又不支持代码中所示的变量,所以最后通过以下代码实现:
    链接地址:
    String[][] contentUrl={
    {"question_input.jsp","question_query.jsp","question_statistics.jsp"},
    {"xxx1.jsp","xxx2.jsp"},
    {"xxx3.jsp","xxx4.jsp"},
    {"xxx5.jsp","xxx6.jsp","xxx7.jsp"}};
    子页面的显示:
    <jsp:include page="<%=contentUrl[pageId][contentId]%>"/>
    在子页面中用s:action调用action:
    <s:action name="QuestionInfo" />
    <%
    List<Difficulty> difficulty = (List<Difficulty>) request
    .getAttribute("difficulty");
    List<QuestionType> questionType = (List<QuestionType>) request
    .getAttribute("questionType"); if (difficulty == null || questionType == null)
    out.println("数据库访问出错,无法显示正确结果.");
    else {
    %>
    <!-- start content,省略 -->