2016-07-29 89 views
-1

我正在实施一个小的struts 2 web应用程序,而我得到上述异常我是struts 2的新手。我已经看到来自堆栈上的流和其他网站的一些建议。我尝试了所有的建议,但仍然无法解决我的问题。没有为命名空间/和操作名称映射的操作。 - [未知位置]

这里是我的strust.xml并保存在WEB-INF/clasess中。

<struts> 
<constant name="struts.devMode" value="true" /> 
    <package name="default" namespace="/" extends="struts-default"> 
     <action name="Login"> 
      <result>pages/login.jsp</result> 
     </action> 

     <action name="Welcome" class="com.tcs.action.DemoAction"> 
      <result name="SUCCESS">pages/welcome.jsp</result> 
     </action> 
    </package> 

</struts> 

这里是我的动作类。

package com.tcs.action; 

public class DemoAction { 


    private String userName; 

    public String getUserName() { 
     return userName; 
    } 

    public void setUserName(String userName) { 
     this.userName = userName; 
    } 

    public String execute(){ 

     return "SUCCESS"; 
    } 

} 

我不停的login.jsp和的welcome.jsp内的webapp/pages文件夹 这里是我的login.jsp

<%@ page contentType="text/html; charset=UTF-8"%> 
<%@ taglib prefix="s" uri="/struts-tags"%> 
<html> 
<head></head> 
<body> 
    <h1>Struts 2 Hello World Example</h1> 

    <s:form action="Welcome"> 
     <s:textfield name="userName" label="Username" /> 
     <s:submit /> 
    </s:form> 

</body> 
</html> 

和的welcome.jsp

<%@ page contentType="text/html; charset=UTF-8"%> 
<%@ taglib prefix="s" uri="/struts-tags"%> 
<html> 
<head></head> 
<body> 
    <h1>Struts 2 Hello World Example</h1> 

    <h2> 
     Hello 
     <s:property value="userName" /> 
    </h2> 

</body> 
</html> 

和我希望我添加了所有与struts相关的jar,因为我没有找到任何未找到的类或没有找到类def的异常。 我希望我在很多地方问我已经存在的问题,但我仍然没有解决问题。

+0

也在您的 login.jsp中包含相同的名称空间属性。 – Abhay

+0

你的意思是“/”我喜欢这个,但我仍然得到同样的问题 – suri

回答

0

这很有趣,但我必须说我做错了什么http://localhost:8089/StrutsApp 这是我的网址,我忘了添加http://localhost:8089/StrutsApp/Login.action 就是这样。现在它工作正常。

相关问题