日期:2014-05-17  浏览次数:20702 次

struts2页面自动加载s:action,但是不显示内容,急!!!
急急急!!!
打开页面时自动加载action,但是页面上不显示结果,请帮忙看看,谢谢!!!

主jsp页面:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@taglib prefix="s" uri="/struts-tags"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
   
  <base href="<%=basePath%>">
   
  <title>主页面</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 >
  主页面<br>
  <s:action name="mainMenu" executeResult="true">
  <s:property value="#request.temp"/>  
  </s:action> 
   
  </body>
</html>

action的内容:
package srvmis.action;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;

public class mainMenuAction extends ActionSupport {

public String temp;
public String getTemp()
{
return temp;
}
public void setTemp(String temp)
{
this.temp = temp;
}

public String execute() throws Exception
{
temp="Temp Word.";

ServletActionContext.getRequest().setAttribute("temp", temp);

return "success";

}

}

转向的jsp页面:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@taglib prefix="s" uri="/struts-tags"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
  <base href="<%=basePath%>">
   
  <title>主页面2</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>
  主页面2. <br>
  <s:property value="#request.temp"/>
  </body>
</html>


struts.xml的内容:
<?xml version="1.0" en