All,
I am green horn in Struts 2 and need help with struts.xml.
I got the following error when try this URL :
localhost:8080/IteratorKFC/menu or localhost:8080/IteratorKFC/menu.action .
what is wrong ? Incorrect configuration or incorrect URL ?
Thank you for your help and advices.
cid:[email protected]
Strut.xml source ========================================
<?xml version="1.0" encoding="UTF-8" ?>
<!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.action.extension" value=""/> -->
<constant name="struts.devMode" value="true" />
<package name="IteratorKFC" namespace="/IteratorKFC"
extends="struts-default">
<action name="menu" class="iteratorkfc.IteratorKFCAction"
method="execute">
<result
name="success">pages/iteratorkfc.jsp</result>
</action>
</package>
</struts>
ItertorKFCAction java ==========================================
package iteratorkfc;
import java.util.*;
import com.opensymphony.xwork2.ActionSupport;
public class IteratorKFCAction extends ActionSupport{
private List<String> comboMeals;
public List<String> getComboMeals() {
return comboMeals;
}
public void setComboMeals(List<String> comboMeals) {
this.comboMeals = comboMeals;
}
@Override
public String execute() {
comboMeals = new ArrayList<String>();
comboMeals.add("Snack Plate");
comboMeals.add("Dinner Plate");
comboMeals.add("Colonel Chicken Rice
Combo");
comboMeals.add("Colonel Burger");
comboMeals.add("O.R. Fillet Burger");
comboMeals.add("Zinger Burger");
return SUCCESS;
}
}
Jsp ============================================
<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<title><s:text name="Struts2 Iterator "/></title>
</head>
<body>
<h1>Struts 2 Iterator tag example</h1>
<h3>Simple Iterator</h3>
<ol>
<s:iterator value="comboMeals">
<li><s:property /></li>
</s:iterator>
</ol>
<h3>Iterator with IteratorStatus</h3>
<table>
<s:iterator value="comboMeals" status="comboMealsStatus">
<tr>
<s:if test="#comboMealsStatus.even == true">
<td style="background: #CCCCCC"><s:property/></td>
</s:if>
<s:elseif test="#comboMealsStatus.first == true">
<td><s:property/> (This is first value) </td>
</s:elseif>
<s:else>
<td><s:property/></td>
</s:else>
</tr>
</s:iterator>
</table>
</body>
</html>
Tri Quan