这些是我与AccessDenied.jsp
and一起创建的文件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>
单击提交按钮后,它不会进入下一页。