我是JSP的初學者,我試圖用我的數據庫中的一些值填充表格!返回的值是一個包含特殊字符的字符串,在雙重分割後,我嘗試將值傳遞給表!問題是即使我嘗試了什麼都沒有發生,並且我的表仍然是空的,即使這些方法返回了正確的值!問題可能出現在html中,但我找不到任何解決方法!任何想法都會受到歡迎!JSP表格不顯示db的值
我的代碼:
<table id="seller_table" border="1">
<tr>
<th>House id </th>
<th>Sell</th>
<th>Rent</th>
<th>Surface </th>
<th>Type of Building </th>
<th>Public Costs </th>
<th>Year of Build/Renovation </th>
<th>Type of Heat </th>
</tr>
<%
String line;
int counter=0;
int i = 0;
if(Souli.hoho()!=null){
counter = 0 ;
for(i=0;i<Souli.hoho().length();i++){
if(Souli.hoho().charAt(i) == '$'){
counter++;
}
}
String[] lines = Souli.hoho().split("\\$");
for(i=0;i<=counter-1;i++){
line = lines[i];
String[] kati = line.split("#");
%>
<tr>
<td><%=kati[i]%></td>
<td><%=kati[i+2]%></td>
<td><%=kati[i+1]%></td>
<td><%=kati[i+4]%></td>
<td><%=kati[i+3]%></td>
<td><%=kati[i+9]%></td>
<td><%=kati[i+5]%></td>
<td><%=kati[i+6]%></td>
</tr>
</table>
<%}}%>
爲什麼不簡單'for(String line:lines){...}'而不是2個週期?你爲什麼使用'kati [i + 2]',其中'i'是'lines []'數組的索引?那是對的嗎? 'lines []'和'kati []'是不同的數組。 – gooamoko 2014-09-03 13:57:15
我不知道它可以給我一個例子嗎? – gimbo 2014-09-03 13:58:47
[避免使用scriptlets。](https://stackoverflow.com/questions/3177733/how-to-avoid-java-code-in-jsp-files?rq=1) – GriffeyDog 2014-09-03 14:03:24