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" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="srvmis" extends="struts-default">
<action name="login" class="srvmis.action.loginAction">
<result name="input">/login.jsp</result>
<result name="success">/mainmenu.jsp</result>
<result name="failure">/login.jsp</result>
</action>
<action name="mainMenu" class="srvmis.action.mainMenuAction">
<result name="success">/mainmenushow.jsp</result>
</action>
</package>
</struts>
[解决办法]
你代码里就有好几处不规范,
1。类名大写
2。属性public???那还要get和set干什么?
3。你的temp到底要通过什么方式来使用?又是public,又是get,set,又来了一个ServletActionContext.getRequest().setAttribute("temp", temp);??谜
[解决办法]
楼上的指出了问题,就要同时告诉解决的方法啊,提了不解,不还是谜吗!