以下是我的doPost代码:
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//String Referer = request.getHeader("Referer") ;
//System.out.println("the refering page is " + Referer + " @ line 66of producerController.doPost()");
String url="";
HttpSession session = request.getSession(true);
RequestDispatcher rd = getServletContext().getRequestDispatcher("/isSessionNewController");
rd.include(request, response);
FieldmanFunctions fmf = new FieldmanFunctions();
ArrayList prod_list = new ArrayList();
prod_list = fmf.getProducerList(info.getPlant_ID());
request.setAttribute("producer_list", prod_list); // this sets the attribute(parm) to call array list by the JSP
url=properties.getProperty("fieldman.page.template");
System.out.println(prod_list.size() + " is the size of prod_list @ line 130 of fieldman controller");
try{
rd = getServletContext().getRequestDispatcher(url);
rd.forward(request, response);
}catch(Exception e){
System.out.println(e);
}
}
这是我用来获取结果集的Java方法
public ArrayList getProducerList(String Plant_ID){
System.out.println("the following is the producer parm being passed in: "+Plant_ID+" @line 24 of FieldmanFunctions.getProducerTests ");
ArrayList al = new ArrayList ();
StringBuffer stmt = new StringBuffer();
ResultFormBean rfb = new ResultFormBean(); // stmt = create a connection
stmt.append("call labapp.fieldman_pl('"+Plant_ID+"')");
ResultSet rs = rfb.RS(stmt.toString());
try{
while (rs.next()){
FieldmanListProducersBean flpb = new FieldmanListProducersBean();
if(rs.getString("log_id4")!=null){
flpb.setProducer_number(rs.getString("log_id4").trim());}
if(rs.getString("name")!=null){
flpb.setProducer_name(rs.getString("name").trim());}
if(rs.getString("company_id")!=null){
flpb.setCompany_id(rs.getString("company_id").trim());}
al.add(flpb);
}
}catch(Exception e){
System.out.println(e);
}
rfb.CloseConn(rs);
return al;
}
这是我的bean代码:
public class FieldmanListProducersBean {
private String producer_number = "";
private String producer_name = "";
private String company_id = "";
private int producer_list_size =0;
public String getProducer_number() {
return producer_number;
}
public void setProducer_number(String producer_number) {
this.producer_number = producer_number;
}
public String getProducer_name() {
return producer_name;
}
public void setProducer_name(String producer_name) {
this.producer_name = producer_name;
}
public String getCompany_id() {
return company_id;
}
public void setCompany_id(String company_id) {
this.company_id = company_id;
}
public int getProducer_list_size() {
return producer_list_size;
}
}
这是我的JSP页面:
<jsp:useBean id="UserInfo" class="com.dallasma.my.session.UserInfo" scope="session" />
<%@taglib uri="/WEB-INF/app.tld" prefix="app" %>
<script type="text/javascript" src="/javascript/ajax_functions.js"></script>
<%@taglib uri="http://java.sun.com/jstl/core" prefix="c"%>
<select name ="producer_list">
<option>producer_list</option>
<c:forEach var="pl" items="${producer_list}">
<option value="${pl.LOG_ID4}">${pl}</option>
</c:forEach>
</select>
<table id="producer_list">
<tr id="header">
<td>Producer Number</td>
<td>Name</td>
<td>Company ID</td>
</tr>
<c:forEach items="${producer_list}" var="pt" varStatus="i">
<c:set var="background_color" value="#fff"/>
<c:set var="border_color" value="black"/>
<c:set var="v" value=""/>
<tr class="producer_list" id="<c:out value="${i.count}_row"/>" style="border:1px solid black;display:block;">
<td style="text-align:center;"><c:out value="${pt.producer_number}"/></td>
<td><c:out value="${pt.producer_name}"/></div></td>
<td><c:out value="${pt.company_id}"/></div></td>
</tr>
</c:forEach>
</table>
以下是我的结果......我在下拉列表中做错了什么? 你还会在results.png的后台看到表格填充正常。
是
<option value="${pl.LOG_ID4}">${pl}</option>
现在低于
<option><c:out value="${pl.producer_number} - ${pl.producer_name}"></c:out> </option>
这将显示为“数字 - 名称”
答案 0 :(得分:0)
我假设您要在select元素中显示生产者名称。
如果您想使用$ {pl}来显示名称,则需要在Object
类中覆盖Producer
类的toString()方法。
否则,你需要这样做
<option value="${pl.producer_number}">${pl.producer_name}</option>