/*
Title: Struts : Essential Skills (Essential Skills)
Authors: Steven Holzner
Publisher: McGraw-Hill Osborne Media
ISBN: 0072256591
*/
//index.jsp
<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib uri="/tags/struts-logic" prefix="logic" %>
<html:html locale="true">
<head>
<title>A Welcome Page</title>
<html:base/>
</head>
<body bgcolor="white">
<h1>A Sample Welcome Page</h1>
<logic:notPresent name="org.apache.struts.action.MESSAGE" scope="application">
<font color="red">
ERROR: Application resources not loaded -- check servlet container
logs for error messages.
</font>
</logic:notPresent>
<html:form action="Data">
Please click the button:
<html:submit />
</html:form>
</body>
</html:html>
//result.jsp
<html>
<head>
<title>A Results page</title>
</head>
<body>
<h1>A Sample Results Page</h1>
<%= request.getAttribute("DATA") %>
</body>
</html>
package ch02;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.*;
public class DataForm extends ActionForm {
public ActionErrors validate(ActionMapping mapping,
HttpServletRequest request) {
return new ActionErrors();
}
}
package ch02;
//import ch02.DataForm;
import java.io.IOException;
import javax.servlet.*;
import javax.servlet.http.*;
import org.apache.struts.action.*;
public class DataAction extends Action {
public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {
String text = "No worries.";
String target = new String("success");
request.setAttribute("DATA", text);
return (mapping.findForward(target));
}
}
|