OGNL配置文件出现问题,紧急求助各位!

Areaze 2016-04-09 05:39:28
参考的马士兵STRTUS2的OGNL教程 里面配置方面没有搞清楚,然后跟着做,设置完之后部署运行,发现浏览器输入http://localhost:8080/Struts2_0100_Test/ognl?username=a&password=d 后无法跳转,显示404错误,之前做的struts2各种实验跳转都没问题,就是搞不懂到底错在了哪里,想了一天,求论坛里的大大们给看一下,多谢了!

IDE里面的文件关系




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="false" />
<constant name="struts.devMode" value="true" />
<constant name="struts.ognl.allowStaticMethodAccess" value="true"></constant>
<include file="ognl/ognl.xml"/>

</struts>



ognl.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="ognl" extends="struts-default">
<action name="ognl" class="ognl.OgnlAction">
<result>/ognl.jsp</result>
</action>
<action name="test" class="ognl.TestAction">
<result type="chain">ognl</result>
</action>
</package>
</struts>



User.java

package ognl;
import com.opensymphony.xwork2.ActionSupport;
public class ognlAction extends ActionSupport{
@Override
public String execute() throws Exception {

return "success";
}
private static final long serialVersionUID = 1L;

private User user;
private String password;
private String username;


public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}




}



web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>


<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>

<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>



</web-app>
...全文
119 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
Areaze 2016-04-10
  • 打赏
  • 举报
回复
引用 3 楼 qnmdcsdn 的回复:
看起来配置没什么问题,检查一下项目名大小写,还有就是ognl.xml中配一个namespace试试
多谢 原来是IDE需要重新部署以下才能正常工作
  • 打赏
  • 举报
回复
看起来配置没什么问题,检查一下项目名大小写,还有就是ognl.xml中配一个namespace试试
Areaze 2016-04-09
  • 打赏
  • 举报
回复
引用 楼主 wpfdh 的回复:
参考的马士兵STRTUS2的OGNL教程 里面配置方面没有搞清楚,然后跟着做,设置完之后部署运行,发现浏览器输入http://localhost:8080/Struts2_0100_Test/ognl?username=a&password=d 后无法跳转,显示404错误,之前做的struts2各种实验跳转都没问题,就是搞不懂到底错在了哪里,想了一天,求论坛里的大大们给看一下,多谢了! IDE里面的文件关系 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="false" />
    <constant name="struts.devMode" value="true" />
    <constant name="struts.ognl.allowStaticMethodAccess" value="true"></constant>
	<include file="ognl/ognl.xml"/>
    
</struts>
ognl.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="ognl" extends="struts-default">
        <action name="ognl" class="ognl.OgnlAction">
            <result>/ognl.jsp</result>
        </action>
        <action name="test" class="ognl.TestAction">
            <result type="chain">ognl</result>
        </action>
    </package>
</struts>
User.java
package ognl;
import com.opensymphony.xwork2.ActionSupport;
public class ognlAction extends ActionSupport{
	@Override
	public String execute() throws Exception {
		
		return "success";
	}
	private static final long serialVersionUID = 1L;
	
	private User user;
	private String password;
	private String username;
	
	
	public String getUsername() {
		return username;
	}
	public void setUsername(String username) {
		this.username = username;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	
	
	
	
}
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 
	xmlns="http://java.sun.com/xml/ns/javaee" 
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
	http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
  
 
  <filter>
        <filter-name>struts2</filter-name>
        <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
    </filter>

    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    
    

</web-app>
你好 我是跟着马士兵的教程走的 里面没说调用的方法
  • 打赏
  • 举报
回复
ognlaction里边的代码是啥,没指定调用哪个方法吧

67,514

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧