逻辑:迭代器不工作
我是 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>
我的dao:
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;
}
}
我的Action类:
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);
}
}
I am new to struts please help me to find out the error.my error like value does not parse from data base.while im executing the page some empty value.please find out this mistake. I could not iterate the value.
What i am doing wrong?
My jsp page:
<%--
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>
MY dao:
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;
}
}
My persistence class:
/*
* 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;
}
}
My Action class:
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);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
乍一看,我发现您在代码中犯了以下错误:
html:option
中所做的那样)。而是使用html:options
或html:optionsCollection
任何你认为好的东西。我推荐html:options
因为它与您想要做的非常相似。这可能会解决您的问题。
编辑 - 注意:您不需要实现
logic:iterate
来获取选择的选项。At first look, I found that You have made following mistake in your code
html:option
). Instead usehtml:options
orhtml:optionsCollection
whatever you feel is good. I recommendhtml:options
since it is very much similar to what you want to do.This may solve your problem.
Edited - Note: You do not need to implement
logic:iterate
for taking options of the select.