【发布时间】:2016-06-10 13:25:27
【问题描述】:
我在 JSP 中使用 Struts2 标记。下面是Action 类。
package com.action;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.List;
import com.opensymphony.xwork2.ActionSupport;
public class EmpLeavePlan extends ActionSupport{
private String bankId;
private String empName;
private String monthYear;
private String leaves;
private Map<String,String> bankIds;
public String display() {
return "SUCESS";
}
public String getDefaultSearchEngine() {
return "yahoo.com";
}
public String execute() throws Exception
{
bankIds = new HashMap<String,String>();
bankIds.put("1541742","h6");
bankIds.put("1541742","eft");
bankIds.put("1394842","dfd");
bankIds.put("1541742","dfee");
return "SUCCESS";}
public String getBankId() {
return bankId;
}
public Map<String, String> getBankIds() {
return bankIds;
}
public void setBankIds(Map<String, String> bankIds) {
this.bankIds = bankIds;
}
public void setBankId(String bankId) {
this.bankId = bankId;
}
public String getEmpName() {
return empName;
}
public void setEmpName(String empName) {
this.empName = empName;
}
public String getMonthYear() {
return monthYear;
}
public void setMonthYear(String monthYear) {
this.monthYear = monthYear;
}
public String getLeaves() {
return leaves;
}
public void setLeaves(String leaves) {
this.leaves = leaves;
}}
JSP:
<%@ taglib uri="/struts-tags" prefix="s" %>
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css">
<script>
$(function() {
var currentDate = new Date();
$("#datepicker").datepicker( {
changeMonth: true,
changeYear: true,
showButtonPanel: true,
dateFormat: 'MM yy'
/* onClose: function(dateText, inst) {
$(this).datepicker('setDate', new Date(inst.selectedYear, inst.selectedMonth, 1));
} */
});
$("#datepicker").datepicker("setDate", currentDate);
});
</script>
<style>
.ui-datepicker-calendar {
display: none;
}
.ui-datepicker-year{
width: 70px !important;
height: 25px;
}
.ui-datepicker-month{
width: 60px !important;
height: 25px;
}
.ui-datepicker ui-widget ui-widget-content ui-helper-clearfix ui-corner-all{
width: 213px !important;
}
</style>
<h1> Leave Plan Management!!! </h1>
<body style="background-color:lightgrey;">
<s:form action="bankgen">
<s:textfield name="monthYear" label="Month/Year" id="datepicker"></s:textfield>
<%-- <s:select label="Select Bank ID"
headerKey="-1" headerValue="Select bank id" list="bankIds"
name="bankIdd" id="bankChange" /> --%>
<s:select label="Select Bank ID"
headerKey="-1" headerValue="Select bank id" list="bankIds"
name="bankId" id="bankChange" />
<s:textfield name="empName" label="Name" id="empName"></s:textfield>
<s:textarea name="leaves" label="Leaves :" id="leaves"></s:textarea>
<s:submit value="save"></s:submit>
</s:form>
</body>
但是,我没有得到输出。在下拉列表中,仅值是反射,而不是 bank id 的键。我希望银行 ID 位于 bank id 列中,键值位于 emp 名称列中。
【问题讨论】:
-
我用“localhost:8080/Demostruts/selectAction.action”来初始化url,而不是直接调用jsp。我需要在下拉列表中生成银行 ID,并在另一个字段中生成相应的 empName。所以,我使用了hashmap。在struts html标签中有“list”属性..list键和列表值。但我不太确定如何在下面的字段中打印相应的 empName
-
您将打印
empName,但它尚未初始化。它不会被打印出来。 -
你能解释一下吗..
-
不清楚
I want the bank ids to be in the bank id column and the key values to be in the emp name column。请澄清您的具体问题或添加其他详细信息以准确突出您的需求。正如目前所写的那样,很难准确地说出你在问什么。请参阅“如何提问”页面以获得澄清此问题的帮助。 -
银行 ID 应显示在下拉列表中 @roman C 。并且相应的银行名称应自动填写在 empName 字段中。这是预期的输出。
标签: java jquery jsp struts2 struts-tags