快崩潰了,在家里做畢設一個bug能卡一天。。這都什么時候了畢業論文老師還不讓我開始寫。。請前輩們教教我
問題如下
org.apache.jasper.JasperException: Unable to compile class for JSP:
JSP檔案:[/./showhistory.jsp] 的第 [56] 行發生了一個錯誤
The constructor History(String, String, float, float, float, float, Date, String) is undefined
package floyd;
import java.util.Date;
public class History {
public int historyId;
public String username;
public float length_preference;
public float traffic_preference;
public float time_preference;
public float crossing_preference;
public String datetime;
public String historypath;
@Override
public String toString() {
return "History [username=" + username + ", length_preference=" + length_preference + ", traffic_preference="
+ traffic_preference + ", time_preference=" + time_preference + ", crossing_preference="
+ crossing_preference + "]";
}
public History(String a,
float b,
float c,
float d,
float e){
username = a;
length_preference = b;
traffic_preference = c;
time_preference = d;
crossing_preference = e;
}
public History(
int a ,
String b,
float c,
float d,
float e,
float f,
String g,
String h
){
historyId = a;
username = b;
length_preference = c;
traffic_preference = d;
time_preference = e;
crossing_preference = f;
datetime = g;
historypath = h;
}
public History(){
}
}
/code]
[code=html]
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"
import="java.sql.*"
import="java.util.*"
import="floyd.*"
%>
<html>
<head>
<!-- <link rel="stylesheet" href="https://bbs.csdn.net/CarControllSystem/layui/layui/css/layui.css"/> -->
<!-- <script type="text/javascript" src="https://bbs.csdn.net/CarControllSystem/layui/layui/layui.all.js"></script> -->
<!-- <script src="https://bbs.csdn.net/CarControllSystem/layui/layui/layui.js"></script> -->
<title>Title</title>
</head>
<body background="backgroundpic.jpg">
<% request.setCharacterEncoding("utf-8");
Object name = session.getAttribute("name") ;
Object password= session.getAttribute("password");
%>
<%
String URL ="jdbc:mysql://localhost:3306/carcontrollner";
final String USERNAME ="root";
final String PWD = "723428";
try{
Class.forName("com.mysql.jdbc.Driver");
}catch(Exception e){}
Connection connection = DriverManager.getConnection(URL,USERNAME,PWD) ;
String sql ="select * from history where username=?";
PreparedStatement pstmt = connection.prepareStatement(sql);
pstmt.setObject(1, name);
ResultSet rs = pstmt.executeQuery();
History history= new History();
List<History> historys = new ArrayList<>();
while(rs.next()) {
history = new History(rs.getInt("history_id"),rs.getString("username"),rs.getFloat("length_preference"),rs.getFloat("danger_preference"),rs.getFloat("time_preference"),rs.getFloat("crossing_preference"),rs.getString("datetime"), rs.getString("historypath"));
historys.add(history);
}
%>
<div >Int
<!-- 內容主體區域 -->
<p align="center">用戶資訊管理</p>
<table width="64%" border="1" align="center" cellspacing="0" class="l_table_1 table" id="table_1">
<tr>
<td width="8%" align="center">記錄ID</td>
<td width="8%" align="center">用戶名</td>
<td width="20%" align="center">歷史路線</td>
<td width="12%" align="center">距離偏好值</td>
<td width="12%" align="center">時間偏好值</td>
<td width="12%" align="center">安全偏好值</td>
<td width="12%" align="center">拐點偏好值</td>
<td width="12%" align="center">駕駛時間戳</td>
<td width="8%" colspan="2" align="center">操作</td>
</tr>
<%
int count=0;
for (History a:historys) {
count++;
String id=a.username;
%>
<tr>
<td><%= a.historyId %></td>
<td><%= a.username %></td>
<td><%=a.historypath %></td>
<td><%=a.length_preference %></td>
<td><%=a.time_preference %></td>
<td><%=a.traffic_preference%></td>
<td><%=a.crossing_preference %></td>
<td><%=a.datetime%></td>
<td><a href="https://bbs.csdn.net/topics/form_historyupdate.jsp?name= &history_id=">更新 </a></td>
<td><a href="https://bbs.csdn.net/topics/historydelete.jsp?name= &history_id=">洗掉 </a></td>
</tr>
<% }
%>
</table>
</div>
</body>
<html>
uj5u.com熱心網友回復:
注意引數型別,你使用的是History(String, String, float, float, float, float, Date, String),第一個引數是string,但你class中定義的是int,還有后面的Date型別,使用時就保持型別一致
uj5u.com熱心網友回復:
您好,我在第134行定義的就是int型別,所以不明白為什么系統會報錯
uj5u.com熱心網友回復:
先把134、135兩行注釋掉,看看還報不報錯,如果報錯,可能是其它地方的問題,如果不報錯,可以是你獲取的值有空的
uj5u.com熱心網友回復:
您好!注釋掉確實不報錯了,但是我資料庫里都是有值的為何會獲取空值呢
uj5u.com熱心網友回復:
新發現情況供您參考,那一行陳述句如果去掉historyId也不報錯,可是加上之后就不行了
uj5u.com熱心網友回復:
你把rs.getInt("history_id")改成Interger.parseInt(rs.getString("history_id"));不行的話,你就單獨列印一下rs.getInt("history_id"),看看是不是獲取的值為null什么的,這個時候給一個默認值(或者說是資料庫中保存的資料有誤)
uj5u.com熱心網友回復:
會顯示Integer不可試別,我放棄實體化之后曾打算以history.屬性分別賦值,卻會顯示history不可識別為變數(明明126行已經建立過了)。
我現在耍了個小聰明,放棄直接取出id,而是改為在jsp頁面將取出的每個記錄重新賦予id,如此若是我演示時每次刪去最后一條記錄,則似乎與直接取出相同效果,若是取中間,則會導致頁面顯示的id與資料庫中id不符,下次再次操作會誤操作。無法,我沒有時間了
uj5u.com熱心網友回復:
Integer是java.lang包里的,不可能識別不了,或者你匯入這個包,另外你的id是什么?是int型別的嗎,數字會不會很大,在回圈里不做其它操作,只列印一下id,用rs.getString("history_id")列印,看看輸出的是什么
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/43806.html
標籤:應用服務器
