Struts 2 操作错误 - 无法继续下一页

问题描述 投票:0回答:1

这些是我与

AccessDenied.jsp
HelloWorld.jsp
一起创建的文件,但代码无法运行。

package com.Struts;

import com.opensymphony.xwork2.ActionSupport;

public class HelloWorldActionSupport extends ActionSupport {
 private String name;

public HelloWorldActionSupport() {
}

@Override
public String execute() throws Exception
{
    if("SECRET".equals(name))
    {
        return SUCCESS;
    }
    else
    {
        return ERROR;
    }
}

public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}
}

struts.xml
文件:

    <!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">

    <struts>
    <!-- Configuration for the default package. -->
    <constant name="struts.devMode" value="true"/>
    <package name="hello" extends="struts-default">
    <action name="helloWorldActionSupport" class= "com.Struts.HelloWorldActionSupport">
    <result name="success">/HelloWorld.jsp</result>
    <result name="error">/AccessDenied.jsp</result>
    </action>
    </package>
    </struts>

index.jsp
文件:

    <%@page contentType="text/html" pageEncoding="UTF-8"%>
    <%@taglib prefix="s" uri="/struts-tags" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Hello World</title>
    </head>
    <body>
    <h1>Hello World from Struts-2</h1>
    <s:action name="helloWorldActionSupport" executeResult="true">
    <label for="name">Please Enter Your Name: </label><br/>
    <input type="text" name="name"/>
    <input type="submit" value="Say Hello"/>
    </s:action>
    </body>
    </html>

我点击提交按钮后,没有进入下一页。

java jsp configuration struts2
1个回答
1
投票

使用此代码

<s:form action="helloWorldActionSupport" method="POST">
  <label for="name">Please Enter Your Name: </label><br/>
  <input type="text" name="name"/>
  <input type="submit" value="Say Hello"/>
</s:form>
© www.soinside.com 2019 - 2024. All rights reserved.