在Struts 2中从JSP调用Java方法 [英] Calling Java method from JSP in Struts 2
本文介绍了在Struts 2中从JSP调用Java方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想调用Java方法,该方法将向我返回数组列表,并且希望将该数组列表添加到JSP的下拉列表中.当用户从下拉列表中选择一个值时,该值将存储在变量类型中
I want to call Java method which returns me the array list and I want to add that array list to the drop-down list in JSP. When user select one value from the drop-down list that value is stored in the variable type
<form action="Config.action" method="post">
<table width="600" height="34" align="center" border="1" bgcolor="#CCCCCC"><br>
<%
Config c = new Config();
ArrayList<String> names = c.populate();
out.print("<table> <tr><select>");
for (String s : names)
{
out.print("<option value="+s+">"+s+"</option>");
}
%>
</select></table>
推荐答案
使用动作属性获取/设置名称
Use action properties to get/set the names
private String name;
//getter and setter
public ArrayList<String> getNames(){
Config c = new Config();
return c.populate();
}
JSP:
<form action="Config.action" method="post">
<table width="600" height="34" align="center" border="1" bgcolor="#CCCCCC"><br>
<s:select name="name" list="names"/>
</table>
</form>
这篇关于在Struts 2中从JSP调用Java方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文