Reputation: 1
These are the files that I have created along with the AccessDenied.jsp
and HelloWorld.jsp
, but the code doesn't run.
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
File:
<!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
File:
<%@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>
After I click on the submit button, it doesn't proceed to the next page.
Upvotes: -1
Views: 276
Reputation: 1
Use this code
<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>
Upvotes: 1