Tutorial - step 4: create all actions and views

Linking views to actions

Once the first action and view are created, we need to add links from our view to a next page.

Next page will be placed (its view and its action) in "Hello World" package. Then we need to create a link from init view to "Hello World" package.

Just drag'n drop a link from initial view to Hello World package reference (fill link parameters as usual and click ok):

Note: linking from view to "Hello World" package enables to display initial view reference inside "Hello World" package.

Building helloworld package

Enter in the "Hello World" package.

Note that this package is empty, but it contains references to Init package, Init view and close package.

Repeat previous operations and create a "hello world" action:

Note that you may use the "browse" button to choose the existing Action class:

Do not forget to create the target method (double-click on action node):

Draw a link from Init view to hello-world view and name it "next":

Re-open init.jsp view (double click on init view node or its reference), and insert the following line in body:

 Initialization page !<br/>

 <a href="<s:url link="next"/>">Go to hello world</a>

Note: url tag is an extension of the Struts2 URL standard tag. It accepts a new "link" attribute that contains the name of the target link. Here, it is "next".

Note: at the moment, only url tag has been overloaded.

Now, close the init.jsp. Add a new JSP view in Hello World package. Call it hello.jsp:

        <%@ page language="java" contentType="text/html; charset=UTF-8"
            pageEncoding="UTF-8"%>
        <%@ taglib uri="/alveole-struts2" prefix="s" %>
        <!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>Insert title here</title>
        </head>
        <body>
        Hello World !<br/>
        
        <a href="<s:url link="next"/>">Go to close session</a>
        </body>
        </html>

Then draw a link from hello world action to hello world view, named "success", and from hello world view to close package:

Building the close package

Enter the close package:

Create a new struts action:

Create the associated method:

Create the final JSP view (file close.jsp):

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="/alveole-struts2" prefix="s" %>
<!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>Insert title here</title>
</head>
<body>
Session closed !
</body>
</html>

Create a link from hello world to close action and name it "next". Create a link from close action* to close view and name it "success":