我尝试创建简单的Web项目工具Spring和Struts2,我想获得一个从applicationContext.xml分配的值。
这是代码。
的web.xml
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
的applicationContext.xml
<beans>
<bean id="PageControllerBean" class="altanovela.action.PageController">
<property name="cetak" value="CETAK TEST"/>
</bean>
</beans>
struts.xml中
<struts>
<package name="pageController" extends="spring-default">
<action name="indexpage" class="PageControllerBean" />
</package>
</struts>
PageController.java
package altanovela.action;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import com.opensymphony.xwork2.ActionSupport;
@Results({
@Result(name=PageController.indexpage,
location="/pages/template/index.ftl", type="freemarker")
})
public class PageController extends ActionSupport{
public static final String indexpage = "indexpage";
private String cetak;
@Action(indexpage)
public String goToIndexPage(){
System.out.println(cetak);
return indexpage;
}
//SETTER AND GETTER...
}
的index.html
<head>
<META HTTP-EQUIV="Refresh" CONTENT="1;URL=indexpage.action">
</head>
当我运行此代码时,我想我会从applicationContext.xml中分配的变量cetak
中获取值,但事实上,我得到null值。我的代码中有什么遗漏吗?