我的struts.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<!-- <constant name="struts.enable.DynamicMethodInvocation" value="false" /> -->
<constant name="struts.devMode" value="true" />
<constant name="struts.ognl.allowStaticMethodAccess" value="true"></constant>
<include file="/com/bisxt/struts2/ognl/ognl.xml"></include>
</struts>
我的ognl.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<package name="ognl" extends="struts=default">
<action name="ognl" class="com.bjsxt.struts2.ognl.OgnlAction">
<result>/ognl.jsp</result>
</action>
</package>
</struts>
我的index.jsp
<?xml version="1.0" encoding="GB2312" ?>
<%@ page language="java" contentType="text/html; charset=GB2312" pageEncoding="GB2312"%>
<%@ taglib uri="/struts-tags" prefix="s" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html charset=GB2312" />
<title>OGNL表达式语言学习</title>
</head>
<body>
访问属性
<s:form action="ognl">
<s:textfield label="请输入名称" key="username"/>
<s:textfield label="请输入名称" key="password"/>
<s:submit />
</s:form>
<li><a href="<s:url action="ognl" />">ognl</a> </li>
</body>
</html>
ognl.jsp
<?xml version="1.0" encoding="GB2312" ?>
<%@ page language="java" contentType="text/html; charset=GB2312" pageEncoding="GB2312"%>
<%@ taglib uri="/struts-tags" prefix="s" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html charset=GB2312" />
<title>OGNL表达式语言学习</title>
</head>
<body>
<ol>
<li>访问值栈中的action的普通属性:username=<s:property value="username" /></li>
<li>访问值栈中的对象的普通属性(get set方法):<s:property value="user.age" /></li>
<li>访问值栈中的对象的普通属性(get set方法):<s:property value="cat.friend.name" /> </li>
<li>访问值栈中的对象的普通方法:<s:property value="password.length()" /> </li>
<li>访问值栈中的对象的普通方法:<s:property value="cat.miaomiao()" /> </li>
<li>访问值栈中action的普通方法:<s:property value="m()" /> </li>
<hr/>
<li>访问静态方法:<s:property value="@com.bjsxt.struts2.ognl.S@s()" /> </li>
<li>访问静态属性:<s:property value="@com.bjsxt.struts2.ognl.S@STR" /> </li>
<li>访问Math静态方法:<s:property value="@@max(2, 3)" /> </li>
<hr/>
<!--<li></li>
<li>访问容器的大小:<s:property value="" /> </li>
<hr />
<li>投影:<s:property value="users.(?#this.age == 1).{age}" /> </li>
<li>投影:<s:property value="users.(^#this.age > 1).{age}" /> </li>
<li>投影:<s:property value="users.($#this.age > 1).{age}" /> </li>
<li>投影:<s:property value="users.($#this.age > 1).{age} == null" /> </li>
<hr />
<li>[]:<s:property value="[0]" /> </li>
-->
</ol>
<s:debug></s:debug>
</body>
</html>
我也页面跳转的时候,一点击那个超链接,的时候无法跳转到ognl.jsp页面
There is no Action mapped for namespace [/] and action name [ognl] associated with context path [/struts2OGNL]. - [unknown location]
com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:185)
org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:63)
org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:37)
com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:58)
org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:552)
org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:99)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:833)
org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:639)
org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1285)
java.lang.Thread.run(Thread.java:619)
------解决思路----------------------
<action name="ognl" class="com.bjsxt.struts2.ognl.OgnlAction" method="方法">
楼主你的OgnlAction里是默认execute()方法?
不是的话要指定
------解决思路----------------------
在struts配置文件中加一个 namespace=“/"
这样:
<package name="ognl" namespace=“/" extends="struts=default">