How do I set up a Struts 1 project?
Author: Deron Eriksson
Description: This Java tutorial walks through setting up a Struts 1 project in Eclipse.
Tutorial created using: Windows XP || JDK 1.5.0_09 || Eclipse Web Tools Platform 1.5.1 || Tomcat 5.5.20


Page: < 1 2 3

(Continued from page 2)

If we click on the 'Go to myTest Success' link, the 'myTest.do?success=ok' goes to the TestAction action. Since the success parameter is present, the request gets forwarded to the success.jsp, as shown below. Notice that the success.jsp is hit while the URL shows the myTest.do action.

http://localhost:8080/struts-demo/myTest.do?success=ok

We can examine our success.jsp below. It contains an <a> tag with href="myStart.do". Clicking on this link would take us back to our myStart.do action, which brings up our start.jsp with myStart.do on the URL.

success.jsp

<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic"%>
<%@ taglib uri="http://struts.apache.org/tags-nested" prefix="nested"%>
<html:html>
<head>
<title>success.jsp</title>
<html:base />
</head>
<body>
<p>Success</p>
<a href="myStart.do">Go to myStart</a>
</body>
</html:html>

On the myStart.do page/action, if we click on 'Go to myTest Failure', the TestAction action fowards us on to the failure.jsp with myTest.do on the URL.

http://localhost:8080/struts-demo/myTest.do

The failure.jsp, like the success.jsp, contains a link back to myStart.do.

failure.jsp

<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic"%>
<%@ taglib uri="http://struts.apache.org/tags-nested" prefix="nested"%>
<html:html>
<head>
<title>failure.jsp</title>
<html:base />
</head>
<body>
<p>Failure</p>
<a href="myStart.do">Go to myStart</a>
</body>
</html:html>

StrutsW has lots of really great features for rapidly developing web applications. In this tutorial, we have only scratched the surface of what Struts can do. I definitely recommend examining the Struts demo applications that can be downloaded from the Struts download site.

Page: < 1 2 3