我是struts的新手请帮我找出错误。我的错误就像值没有从数据库中解析。而我正在执行页面一些空值。请找出这个错误。我无法迭代这个值。
我做错了什么?
我的jsp页面:
<%--
Document : dublicateId
Created on : Aug 8, 2011, 5:36:20 PM
Author : Trainnee
--%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-logic" prefix="logic" %>
<%@ page import="com.rec.bookbank.persitencejavafile.DuplicateIdObject" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page import="java.util.*;"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<LINK REL="stylesheet" href="<%=request.getContextPath()%>/css/dublicate.css">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<html:form action="/id" ></html:form>
<div id="container">
<div id="header">
<table width="960">
<tr>
<td id="header1" align="center">
DUBLICATE ID CARD REQUEST
</td><td><a href="/REC_BookBank/jsp/exisitingUser.jsp">Back</a></td>
</tr>
</table>
</div>
<div id="content">
<table cellpadding="10" align="center">
<tr><td>Reason For Requesting Dublicate ID:</td>
<tr><td>
</td><td>
<logic:iterate id="duplicate" name="duplicate" type="com.rec.bookbank.persitencejavafile.DuplicateIdObject">
<html:select property="reason" name="duplicate">
<html:option value='<bean:write property="duplicate" name="reason"/>'/>
</html:select>
</td>
<tr>
<tr><td>Mode of dispatch </td>
<tr><td>
</td><td>
<html:select property="reason" name="duplicate">
<html:option value='<bean:write property="duplicate" name="reason"/>'/>
</html:select>
</logic:iterate>
</td>
<tr>
<td>
Conformation Of Mailing Address:
</td>
<td>
</td>
</tr>
<tr>
<td><font size="3"id="header1">Charges Applicable</font></td>
</tr>
<tr><td>Components </td><td>Amount IN INR</td></tr>
<tr><td>Dublicate Card Charges</td><td><html:text property="cardcharges" value=""/></td>
</tr>
<tr>
<td>Courier Charges
</td><td>
</td>
</tr>
<tr>
<td>Grant Total</td><td>></td>
</tr>
<tr><td><html:submit property="submit" value="paynow" /></td><td><html:button property="" value="Later"/></td></tr>
</table>
</div>
</div>
</body>
</html>
我的道:
package com.rec.bookbank.dao;
import com.rec.bookbank.form.DuplicateIdForm;
import com.rec.bookbank.sessionCfg.HibernateUtil;
import java.util.ArrayList;
import java.util.List;
import org.hibernate.Session;
import org.hibernate.Query;
import com.rec.bookbank.persitencejavafile.DuplicateIdObject;
public class DuplicateIdDAO
{
public static List duplicateidrequest()
{
Session session=null;
try
{
List duplicate=new ArrayList();
session = HibernateUtil.getSession();
System.out.println(" Session :: "+session);
Query query=session.createSQLQuery("{call SP_Duplicate()}");
duplicate = getList(query.list());
System.out.println("in dao getduplicate----"+duplicate);
if(duplicate!=null)
return duplicate;
else
return new ArrayList();
}
catch(Exception e)
{
System.out.println("Exception in duplicateidrequest::"+e);
return null;
}
finally
{
session.close();
}
}
public static List<DuplicateIdObject> getList ( List<Object[]>duplicate )
{
System.out.println("in convertor");
List<DuplicateIdObject>duplicateobjectlist = new ArrayList<DuplicateIdObject>();
for(Object[] array:duplicate)
{
System.out.println("value in method::"+duplicate.size());
DuplicateIdObject duplicateIdObject=new DuplicateIdObject();
duplicateIdObject.setReason(array[0].toString());
duplicateIdObject.setReason(array[1].toString());
duplicateobjectlist.add(duplicateIdObject);
}
return duplicateobjectlist;
}
}
我的持久性课程:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.rec.bookbank.persitencejavafile;
import javax.persistence.Entity;
import javax.persistence.Id;
import java.io.Serializable;
/**
*
* @author Trainnee
*/
@Entity
public class DuplicateIdObject implements Serializable
{
@Id
private int id;
private String reason;
private String dispatch;
private String address;
private String cardcharges;
private String couriercharges;
private String total;
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getCardcharges() {
return cardcharges;
}
public void setCardcharges(String cardcharges) {
this.cardcharges = cardcharges;
}
public String getCouriercharges() {
return couriercharges;
}
public void setCouriercharges(String couriercharges) {
this.couriercharges = couriercharges;
}
public String getDispatch() {
return dispatch;
}
public void setDispatch(String dispatch) {
this.dispatch = dispatch;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getReason() {
return reason;
}
public void setReason(String reason) {
this.reason = reason;
}
public String getTotal() {
return total;
}
public void setTotal(String total) {
this.total = total;
}
}
我的行动课程:
package com.rec.bookbank.action;
import com.rec.bookbank.form.DuplicateIdForm;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForward;
import com.rec.bookbank.Constants.Constants;
import com.rec.bookbank.persitencejavafile.DuplicateIdObject;
import com.rec.bookbank.dao.DuplicateIdDAO;
import java.util.List;
import java.util.ArrayList;
public class DuplicateIdAction extends org.apache.struts.action.Action {
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
DuplicateIdForm duplicateIdForm=(DuplicateIdForm)form;
List<DuplicateIdObject> convert=new ArrayList<DuplicateIdObject>();
convert=DuplicateIdDAO.duplicateidrequest();
System.out.println("list in action::" +convert.size());
request.setAttribute("duplicate", convert);
System.out.print("request in Action::"+request.getAttribute("duplicate"));
return mapping.findForward(Constants.ACTION_FORWARD_SUCCESS);
}
}
答案 0 :(得分:2)
初看起来,我发现您在代码中犯了以下错误
html:option
中所做的那样)。相反,使用html:options
或html:optionsCollection
无论你认为什么是好的。我推荐html:options
,因为它与你想要做的非常相似。 这可以解决您的问题。
已编辑 - 注意:您无需实施logic:iterate
来获取选择权。