我想知道此代码中的错误。
我有一个日期列表,第二个列表包含其他值。 我试图将所有日期列入清单" daStock"列表中的其他值(行,类别,持续时间)" stockss"。我的页面jsp中有一个表。我希望每个日期显示都有自己的值。
<%@page import="model.Stock"%>
<%@page import="model.Operateur"%>
<%@page import="model.Descriptionarret"%>
<%@page import="model.Categoriearret"%>
<%@page import="web.Operation"%>
<%@page import="web.UhtBeans"%>
<%@page import="model.Ligne"%>
<%@page import="java.text.DateFormat"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="java.util.Date"%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.util.Iterator"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html >
<head >
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<meta name="author" content="MWH Team 2" />
<script type="text/javascript" src="fichier/jquery-1.10.2.js"></script>
<script type="text/javascript" src="jquery-ui-1.11.0/jquery-ui.js"></script>
<script type="text/javascript" src="fichier/ajax_js.js"></script>
<script type="text/javascript" src="fichier/calendrier.js"></script>
<link rel="stylesheet" media="screen" type="text/css" title="Design" href="fichier/design.css" />
<link href="./fichier/bootstrap.min.css" rel="stylesheet">
<link href="./fichier/Site.css" rel="stylesheet">
<link rel="stylesheet" href="jquery-ui-1.11.0/jquery-ui.css">
<title>UHT</title>
<script language="javascript">
function showList() {
var select = document.getElementById('liste');
if(select.value == "l1") {
document.getElementById('l1').setAttribute('style','visibility:inline');
} else if(select.value == "l2") {
document.getElementById('l2').setAttribute('style','visibility:inline');
} else {
document.getElementById('l3').setAttribute('style','visibility:inline');
}
}
</script>
</head>
<body >
<script language="JavaScript" type="text/javascript">
function getsupport ( )
{
document.SupportForm.submit() ;
}
</script>
<%
Operateur p = new Operateur();
String info="";
String info1="";
String info2="";
if (session.getAttribute("oppp")==null){%>
<SCRIPT LANGUAGE='JavaScript'>
window.alert('Veuillez vous identifier');
window.location.href='Connexion.jsp';
</SCRIPT>
<% } else {
p = (Operateur) session.getAttribute("oppp");
if (p.getIsadmin().equals("false"))
{
info = p.getNomoperateur();
info2="Operateur";
info1="opera";
}
else
{
info = p.getNomoperateur();
info2="Administrateur";
info1="admin";
}
}
%>
<script language="JavaScript" type="text/javascript">
function getsupport ( )
{
document.SupportForm.submit() ;
}
</script>
<div style="padding-bottom:30px; margin-top:-10px; background-color: green; background-image: url('./fichier/occpp.png');
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
" >
<div> <label style="margin-left:1150px; margin-top:30px; margin-right: 2px; color:#ffffff; font-family: Calibri, sans-serif; "><%=info %><br/><%=info2 %></label></div>
<p style="color:#ffffff; font-size:36px; font-family: Coolvetica Rg;" align="center">Cute Process UHT</p>
</div>
<div class="row-offcanvas row-offcanvas-left">
<div id="sidebar" class="sidebar-offcanvas" style="margin-top:18px; ">
<form name="SupportForm" method="post" action="controle">
<input type="hidden" name="Adminpanel4" />
<ul class="nav nav-pills nav-stacked">
<li><a href="#">Acceuil</a></li>
<li class="active"><a href="Index.jsp">Saisie des Données</a></li>
<li class="active"><a href="Resultats.jsp">Resultats</a></li>
<li id="Adminpanel" ><a href="Ligne.jsp">Gestion des Lignes</a></li>
<li id="Adminpanel1"><a href="Categorie.jsp">Gestion des Categories</a></li>
<li id="Adminpanel2"><a href="Arret.jsp">Gestion des Arrêts</a></li>
<li id="Adminpanel3"><a href="Operateur.jsp">Gestion des Operateurs</a></li>
<li><a href="javascript:getsupport()">Deconnexion</a></li>
</ul>
</form>
</div>
<button class="sidebar-trigger" data-toggle="offcanvas" style="margin-top:18px;"></button>
<div id="main">
<div class=" container-fluid body-content " style="margin-top:10px; ">
<%
UhtBeans uhtBs;
Operation opp = new Operation();
uhtBs = new UhtBeans();
uhtBs.setListeLi(opp.allLigne());
uhtBs.setListeCat(opp.allCategorie());
uhtBs.setListeArr(opp.allArret());
%>
<input type="hidden" name="isSent" id="InputisSent" />
<input type="hidden" id="oop" value="<%=info1 %>" /></td>
<br /><br />
<center>
<h2 align="center" class="button green center" data-toggle="collapse" data-target="#Gestion1" >List</h2>
<br><br>
<center id="Gestion1" class="collapse">
<div id="affichage" style="overflow:auto;">
<script type="text/javascript">
var tableToExcel = (function() {
var uri = 'data:application/vnd.ms-excel;base64,'
, template = '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head><body><table>{table}</table></body></html>'
, base64 = function(s) { return window.btoa(unescape(encodeURIComponent(s))) }
, format = function(s, c) { return s.replace(/{(\w+)}/g, function(m, p) { return c[p]; }) }
return function(table, name) {
if (!table.nodeType) table = document.getElementById(table)
var ctx = {worksheet: name || 'Worksheet', table: table.innerHTML}
window.location.href = uri + base64(format(template, ctx))
}
})()
</script>
<div id="export" ><input type="button" onclick="tableToExcel('testTable2', 'W3C Example Table')" value=" Export to Excel ">
</div>
<p></p>
<center>
<table border="1" id="testTable2" border="1" width=100% class="table table-hover">
<thead>
<tr align="center" >
<th width="50%">Postes</th>
<th>Poste1 (22h-06h)</th>
<th>Poste2 (06h-14h)</th>
<th>Poste3 (14h-22h)</th>
<th>Total Journé</th>
</tr>
</thead>
<%
UhtBeans ub = new UhtBeans();
UhtBeans ub1 = new UhtBeans();
ub.setListDateSt(opp.allDateStock());
ub1.setListSt(opp.allStock());
request.setAttribute("DateStock", ub);
request.setAttribute("stock", ub1);
UhtBeans stockss;
UhtBeans daStock;
daStock = (UhtBeans) request.getAttribute("DateStock");
if(request.getAttribute("stock") != null){
stockss =(UhtBeans) request.getAttribute("stock");
}else {
Operation opers = new Operation();
stockss = new UhtBeans();
stockss.setListSt(opers.allStock());
}
%>
<%
Iterator<Stock> listDat = daStock.getListDateSt().iterator();
while(listDat.hasNext()){
Stock sd =listDat.next();
Iterator<Stock> lists = stockss.getListSt().iterator();
while(lists.hasNext()){
Stock s =lists.next();
%>
<tr>
<th bgcolor="green" class="Date"><%=s.getDate() %></th>
</tr>
<tr align="center" bgcolor="cyan">
<th>DIAGRAMME TEMPS</th>
<th>Durée(min)</th>
<th>Durée(min)</th>
<th>Durée(min)</th>
<th>Durée(min)</th>
</tr>
<tbody id="colonne">
<tr align="center">
<th bgcolor="yellow">Temps Calendrier</th>
<%int d=480; %>
<th id="d" class="Duree"><%=d %></th>
<th ></th>
<th></th>
<th></th>
</tr>
<tr align="right">
<th bgcolor="red">Temps non disponible</th>
<th class="Duree" id="d11"><%
System.out.println("ID DU CATEGORIE EST : "+s.getCategorie());
if (s.getCategorie().equals("0")){
%>
<%=s.getDuree() %>
<%} %>
</th>
<th></th>
<th></th>
<th></th>
</tr>
<tr align="center">
<th bgcolor="yellow">Temps Disponible</th>
<%int d2;
d2=d; %>
<th><%=d2 %></th>
<th></th>
<th></th>
<th></th>
</tr>
<tr align="right">
<th bgcolor="red">Temps disponible non utilisé</th>
<th class="Duree">
<%System.out.println("ID De TDNU EST : "+ s.getCategorie());
if(s.getCategorie().equals("1")){
%><%=s.getDuree()%>
<%} %>
</th>
<th></th>
<th></th>
<th></th>
</tr>
<tr align="center">
<th bgcolor="yellow">Temps d'ouverture</th>
<th></th>
<th></th>
<th></th>
<th></th>
</tr>
<tr align="right">
<th bgcolor="red">Préventif et révision équipement</th>
<th></th>
<th></th>
<th></th>
<th></th>
</tr>
<tr align="right">
<th bgcolor="red">Autres arrêts planifiés non OP</th>
<th></th>
<th></th>
<th></th>
<th></th>
</tr>
<tr align="center">
<th bgcolor="yellow">Temps operationnel</th>
<th></th>
<th></th>
<th></th>
<th></th>
</tr>
<tr align="right">
<th bgcolor="red">Nettoyage</th>
<th></th>
<th></th>
<th></th>
<th></th>
</tr>
<tr align="right">
<th bgcolor="red">Autres arrêts OP planifiés</th>
<th></th>
<th></th>
<th></th>
<th></th>
</tr>
<tr align="center">
<th bgcolor="yellow">Temps de production</th>
<th></th>
<th></th>
<th></th>
<th></th>
</tr>
<tr align="right">
<th bgcolor="red">Arrêts organisationnels</th>
<th></th>
<th></th>
<th></th>
<th></th>
</tr>
<tr align="right">
<th bgcolor="red">Arrêts techniques</th>
<th></th>
<th></th>
<th></th>
<th></th>
</tr>
<tr align="right">
<th bgcolor="red">Arrêts technologiques</th>
<th></th>
<th></th>
<th></th>
<th></th>
</tr>
<tr align="center">
<th bgcolor="yellow">Running time</th>
<th></th>
<th></th>
<th></th>
<th></th>
</tr>
<tr align="center">
<th bgcolor="yellow">Temps net de production</th>
<th></th>
<th></th>
<th></th>
<th></th>
</tr>
<%
}}
%>
</tbody>
<tr><th colspan="5"><br></th></tr>
<tr align="center" bgcolor="cyan">
<th>INDICATEURS DU CUTE</th>
<th colspan="4">Valeur</th>
</tr>
<tr align="center" bgcolor="green">
<th>Efficacité de production (PE)</th>
<th></th>
<th></th>
<th></th>
<th></th>
</tr>
<tr align="center" bgcolor="green">
<th>Efficacité operationnelle (OE)</th>
<th></th>
<th></th>
<th></th>
<th></th>
</tr>
<tr align="center" bgcolor="green">
<th>Efficacité énèrgetique (EE)</th>
<th></th>
<th></th>
<th></th>
<th></th>
</tr>
<tr align="center" bgcolor="green">
<th>Maintenance planifiée (PM)</th>
<th></th>
<th></th>
<th></th>
<th></th>
</tr>
<tr align="center" bgcolor="green">
<th>Nettoyage planifié (CIP)</th>
<th></th>
<th></th>
<th></th>
<th></th>
</tr>
<tr align="center" bgcolor="green">
<th>Arrêts techniques (th)</th>
<th></th>
<th></th>
<th></th>
<th></th>
</tr>
<tr align="center" bgcolor="green">
<th>Arrêts technologiques (TOD)</th>
<th></th>
<th></th>
<th></th>
<th></th>
</tr>
<tr align="center" bgcolor="green">
<th>Utilisation operationnelle (OU)</th>
<th></th>
<th></th>
<th></th>
<th></th>
</tr>
<tr>
</table>
</center>
</div>
</center>
<script>
$('#InputOperateurMail').on("click", function () {
// $('#CC').val($(this).val());
$('#CC').val($('#CC').val()+";"+$(this).val());
});
$( "#InputDate" ).datepicker({
changeMonth: true,
changeYear: true
});
//Le script Ajaaaaaaaaaaaaaaaaaax
$(document).ready(function() {
if ( $("#oop").val()!="admin")
{
$("#Adminpanel").hide();
$("#Adminpanel1").hide();
$("#Adminpanel2").hide();
$("#Adminpanel3").hide();
$("#export").hide();
}
var selectionCount = 1;
$('#Ajouter').on("click", function () {
$.ajax({
type: "GET",
url: "controle?action=Ajouter",
data: {
Date: $("#InputDate").val(),
NomCat: $("#InputNomCat").val(),
Arret: $("#InputArrets option:selected").val(),
Ligne: $("#InputLigne").val(),
Duree: $("#InputDuree").val(),
},
success: function (result) {
$("#affichage").html(result);
}
});
});
//Modifier
$('#Modifier').on("click", function () {
$.ajax({
type: "GET",
url: "controle?action=Modifier",
data: {
Date: $("#InputDate").val(),
NomCat: $("#InputNomCat").val(),
Arret: $("#InputArrets").val(),
Ligne: $("#InputLigne").val(),
Duree: $("#InputDuree").val(),
},
success: function (result) {
$("#affichage").html(result);
}
});
});
//Supprimer
$('#Supprimer').on("click", function () {
$.ajax({
type: "GET",
url: "controle?action=Supprimer",
data: {
Date: $("#InputDate").val(),
NomCat: $("#InputNomCat").val(),
Arret: $("#InputArrets").val(),
Ligne: $("#InputLigne").val(),
Duree: $("#InputDuree").val(),
},
success: function (result) {
$("#affichage").html(result);
}
});
});
//Recherche
$('#Rechercher').on("click", function () {
$("#Retourner").attr('type', 'submit');
$("#Rechercher").attr('type', 'hidden');
$.ajax({
type: "GET",
url: "controle?action=Rechercher",
data: {
Date: $("#InputDate").val(),
},
success: function (result) {
$("#affichage").html(result);
}
});
});
//retourner Affichage
$('#Retourner').on("click", function () {
$("#Retourner").attr('type', 'hidden');
$("#Rechercher").attr('type', 'submit');
$.ajax({
type: "GET",
url: "controle?action=Retourner",
success: function (result) {
$("#affichage").html(result);
}
});
});
//Vider les Inputs
$('#Vider').on("click", function () {
$("#InputDate").val("");
$("#InputNomCat").val("");
$("#InputArrets").val("");
$("#InputLigne").val("");
$("#InputDuree").val("");
});
//Affichage des valeurs dans les Inputs
$('#affichage').on("click", 'tbody tr', function () {
if ($(this).hasClass('selected')) {
selectionCount++;
selectionCount = 1;
}
if (selectionCount == 1) {
$(".selected").removeClass("selected");
$(this).addClass("selected");
var Date = $('.selected').find(".Date").text().trim();
var NomCat = $('.selected').find(".NomCat").text().trim();
var Arret = $('.selected').find(".Arret").text().trim();
var Ligne = $('.selected').find(".Ligne").text().trim();
var Duree = $('.selected').find(".Duree").text().trim();
//changement du couleur
$('#colonne tr').css('background','white');
$("#InputDate").val(Date) ;
$("#InputNomCat").val(NomCat);
$("#InputArrets").val(Arret);
$("#InputLigne").val(Ligne);
$("#InputDuree").val(Duree);
}
});
//Affichage des valeurs dans les Inputs
var i=1;
$( "#espacefournisseur" ).hide();
$( "#espaceF" ).click(function() {
if(i % 2 == 0)
{ $( "#espacefournisseur" ).hide( "slow");
i=i+1;
}else
{ $( "#espacefournisseur" ).show( "slow");
i=i+1;
}});
});
</script>
<!-- Date Pickeeeeeeeer! -->
<!-- Tableau obligatoire ! C'est lui qui contiendra le calendrier ! -->
<table class="ds_box" cellpadding="0" cellspacing="0" id="ds_conclass" style="display: none;">
<tr>
<td id="ds_calclass"></td>
</tr>
</table>
<script type="text/javascript" src="fichier/bootstrap.js"></script>
<script src="fichier/Site.js"></script>
</div>
</div>
</div>
</body>
</html>
&#13;
错误
SEVERE: Servlet.service() for servlet [jsp] in context with path [/Stage-UHT1] threw exception [An exception occurred processing JSP page /Resultats.jsp at line 222
219: <%
220: Iterator<Stock> listDat = daStock.getListDateSt().iterator();
221: while(listDat.hasNext()){
222: Stock sd =listDat.next();
223: Iterator<Stock> lists = stockss.getListSt().iterator();
224: while(lists.hasNext()){
225: Stock s =lists.next();
Stacktrace:] with root cause
java.lang.ClassCastException: java.lang.String cannot be cast to model.Stock
at org.apache.jsp.Resultats_jsp._jspService(Resultats_jsp.java:310)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:313)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
UhtBeans CLass
package web;
import java.util.ArrayList;
import java.util.List;
import model.Categoriearret;
import model.Descriptionarret;
import model.Ligne;
import model.Operateur;
import model.Stock;
public class UhtBeans {
private Ligne ligne = new Ligne() ;
private Categoriearret categorie = new Categoriearret();
private Descriptionarret arret = new Descriptionarret();
private Stock stock = new Stock();
private Operateur operateur = new Operateur();
private boolean login;
private ArrayList<Ligne> listeLi = new ArrayList<Ligne>();
private ArrayList<Categoriearret> listeCat = new ArrayList<Categoriearret>();
private ArrayList<Descriptionarret> listeArr = new ArrayList<Descriptionarret>();
private ArrayList<Stock> listSt = new ArrayList<Stock>();
private ArrayList<Stock> listDateSt = new ArrayList<Stock>();
private ArrayList<Operateur> listOp = new ArrayList<Operateur>();
public ArrayList<Stock> getListDateSt() {
return listDateSt;
}
public void setListDateSt(List<Stock> listDateSt) {
this.listDateSt = (ArrayList<Stock>) listDateSt;
}
//Operateur
public Operateur getOperateur() {
return operateur;
}
public void setOperateur(Operateur operateur) {
this.operateur = operateur;
}
public ArrayList<Operateur> getListOp() {
return listOp;
}
public void setListOp(List<Operateur> listOp) {
this.listOp = (ArrayList<Operateur>) listOp;
}
//Stock
public Stock getStock() {
return stock;
}
public void setStock(Stock stock) {
this.stock = stock;
}
public ArrayList<Stock> getListSt() {
return listSt;
}
public void setListSt(List<Stock> list) {
this.listSt = (ArrayList<Stock>) list;
}
//Arrêt
public Descriptionarret getArret() {
return arret;
}
public void setArret(Descriptionarret arret) {
this.arret = arret;
}
public ArrayList<Descriptionarret> getListeArr() {
return listeArr;
}
public void setListeArr(List<Descriptionarret> listeArr) {
this.listeArr = (ArrayList<Descriptionarret>)listeArr;
}
//Categories
public Categoriearret getCategorie() {
return categorie;
}
public void setCategorie(Categoriearret categorie) {
this.categorie = categorie;
}
public ArrayList<Categoriearret> getListeCat() {
return listeCat;
}
public void setListeCat(List<Categoriearret> listCat) {
this.listeCat = (ArrayList<Categoriearret>)listCat;
}
//Lignes
public Ligne getLigne() {
return ligne;
}
public void setLigne(Ligne ligne) {
this.ligne = ligne;
}
public ArrayList<Ligne> getListeLi() {
return listeLi;
}
public void setListeLi(List<Ligne> listeLi) {
this.listeLi = (ArrayList<Ligne>)listeLi;
}
public boolean isLogin() {
return login;
}
public void setLogin(boolean login) {
this.login = login;
}
}
&#13;
答案 0 :(得分:1)
我认为stockss.getListSt()
会返回一个String列表。因此,将列表元素强制转换为Stock无法工作。这就是您在Stock s =lists.next();