我想做个主页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;"> </div>
</div>
<!-- end page -->
<div id="footer">
<p>©2010 All Rights Reserved. • Design by <a href="http://www.freecsstemplates.org/">Free CSS Templates</a> • Icons by <a href="http://www.famfamfam.com/">FAMFAMFAM</a>.</p>
</div>
</body>
</html>
<%@ 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;"> </div>
</div>
<!-- end page -->
<div id="footer">
<p>©2010 All Rights Reserved. • Design by <a href="http://www.freecsstemplates.org/">Free CSS Templates</a> • Icons by <a href="http://www.famfamfam.com/">FAMFAMFAM</a>.</p>
</div>
</body>
</html>
解决方案 »
- 大家有谁写过java写过触摸屏程序的?
- 2张表同步问题
- 怎样使变量付值??
- 如何架设本地服务器?
- 有几个文章名,每个文章名都是一个超连接,连到另一个jsp页面,如何在此jsp页面获得被点击的文章名
- 用<input type=file...>按钮默认显示的是'参照',如何改变按钮的显示
- 急。用户登陆后,需要在他关闭所有页面后注销其登陆,该怎么做
- 装了TOMCAT后, 不访问数据库的JSP通过浏览, 访问数据库的JSP不能;(附安装过程)
- TOMCAT运行其间的问题,谁能帮我解决一下?万分感谢
- 谁知道哪儿有cloudscape数据库的安装程序?
- struts2页面刷新重复提交
- JSP写入文本文件出现乱码?
<s:action name="%{contentUrl[pageId][contentId]}" executeResult="true"/>
严重: Could not execute action: /
There is no Action mapped for action name . - [unknown location]
<s:action name="%{idUrlAction}" executeResult="true"/>
严重: Could not execute action: /?pageId=0
{"QuestionInfo","question_query.jsp","question_statistics.jsp"},
{"",""},
{"",""}
};在用
<s:action name="%{contentUrl[pageId][contentId]}" executeResult="true"/>
<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;
}
<form="a" action="" xxx></form>
<js...>
function xx(){
var form = document.forms[0];//根据实际情况
form.action="xxxx"
form.submit();
}
我觉得再多2个action也无所谓
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,省略 -->