读书人

action中没执行execute()与prepare()方

发布时间: 2012-08-24 10:00:21 作者: rapoo

action中没有执行execute()与prepare()方法
pagingaction.java

package com.action;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts2.interceptor.ServletRequestAware;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.Preparable;

import java.util.*;

public class pagingAction extends ActionSupport implements Preparable
{

private static int firstPage = 1; //第一页

public void setFirstPage(int firstPage)
{
this.firstPage = 1;
}
public int getFirstPage()
{
return firstPage;
}

@Override
public String execute() throws Exception
{

setFirstPage(int 3);
return "success";

}

@Override
public void prepare() throws Exception
{
setFirstPage(int 2);
}

}


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>

<constant name="struts.enable.DynamicMethodInvocation" value="true" />
<constant name="struts.devMode" value="false" />

<package name="com.action" extends="struts-default" namespace="/test">
<action name="paging" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib prefix="s" uri="/struts-tags" %>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<s:form name="paging" theme="simple" action="paging" validate="true" namespace="/test" >
<table class="table">
<tr>
<td>当前第一页面:<s:property value="firstPage"/> </td>
</tr>
</table>
</s:form>
</body>
</html>


用的是eclipse 开发
然后直接运行paging.jsp页面 得到的:<s:property value="firstPage"/> 的值是空值

为什么 pagingaction.java 中的


@Override
public String execute() throws Exception
{

setFirstPage(int 3);
return "success";

}

@Override
public void prepare() throws Exception
{
setFirstPage(int 2);
}


这两段代码没有执行呢

读书人网 >Web前端

热点推荐