Reputation: 14960
Good day!
I am currently studying Struts 2 and I am quite confused with the xml. I don't know where to start.
I want my index.jsp to go to my Display Action Class So My codes is as follows:
index.jsp
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<META HTTP-EQUIV="Refresh" CONTENT="0;URL=package.action/DisplayContactAction">
</head>
<body>
</body>
</html>
struts.xml
<action name="index">
<result type="redirectAction">
<param name="actionName">HelloWorld</param>
<param name="namespace">/example</param>
</result>
</action>
Can anyone explain to me what the code on the struts.xml above means.
After I redirect my page to the action class, i want it to go to the display.jsp
Action Class
private ArrayList<Contacts> contactsList;
private int id;
private String firstName;
private String lastName;
private String telNumber;
private String email;
public String execute() {
String result = null;
ContactsManager contactsManager = ContactsManager.getInstance();
contactsList = ContactsManager.getContactsList();
result = "success";
return result;
}
Now... How can I pass the value using xml? Also, how can i transfer the data generated on my action class to the jsp?
Thank you.
Upvotes: 0
Views: 1108
Reputation: 11055
Can anyone explain to me what the code on the struts.xml above means.
The following result would redirect to the URL for the HelloWorld action (likely /example/HelloWorld).
<result type="redirectAction">
<param name="actionName">HelloWorld</param>
<param name="namespace">/example</param>
</result>
It calls the getUriFromActionMapping(ActionMapping)
method of the ActionMapper
to determine the URL to redirect to. You could also use a standard redirect type (type="redirect"
).
Also, how can i transfer the data generated on my action class to the jsp?
You'll need a getter to expose the data and then you can access it in the JSP.
Upvotes: 2