Struts 2你好的话

时间:2014-04-06 12:38:22

标签: java struts2

我是struts 2的新手,当你运行hello word例子时我得到了这个错误 HTTP状态404 - 没有映射名称空间/操作名称登录的操作。 我把jsp页面放在wepapp / pages文件夹中,我该如何解决呢?

   @ResultPath(value="/")
   public class HelloController extends ActionSupport{

/**
 * 
 */
private static final long serialVersionUID = 1L;
private String name;

public String getName() {
    return name;
}
public void setName(String name) {
    this.name = name;
}
    @Action(value="/Login",results={@Result(name="success",location="pages/login.jsp")})
public String execute()throws Exception
{
    return "success";
}
   }

的web.xml

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

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

和这个pom文件

<dependencies>
<dependency>
  <groupId>junit</groupId>
  <artifactId>junit</artifactId>
  <version>3.8.1</version>
  <scope>test</scope>
 </dependency>
    <dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.1</version>
 </dependency>

     <dependency>
      <groupId>org.apache.struts</groupId>
  <artifactId>struts2-core</artifactId>
  <version>2.1.8</version>
</dependency>

<dependency>
      <groupId>org.apache.struts</groupId>
  <artifactId>struts2-convention-plugin</artifactId>
  <version>2.1.8</version>
 </dependency>

 <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.16</version>
    </dependency>

    <dependency>
    <groupId>javax</groupId>
    <artifactId>javaee-api</artifactId>
    <version>7.0</version>
    <scope>provided</scope>
    </dependency>

 </dependencies>

3 个答案:

答案 0 :(得分:0)

您必须在网址中调用操作名称:

http://localhost:<your-port>/Login.action

同时将操作名称更改为:

@Action(value="Login" ....

答案 1 :(得分:0)

您的过滤器已弃用。从Struts 2.1.3开始,you need to changeFilterDispatcherStrutsPrepareAndExecuteFilter

迁移到至少2.3.16也是很好的,以避免多年来发现和修补的安全问题。

2.1很老了......

答案 2 :(得分:0)

我解决了它,我必须在打包的命名操作中添加HelloController类,因为struts 2扫描位于打包名为“struts,struts2,action或actions”的带注释的类