我是JSP的初学者,正在尝试用数据库中的某些值填充表!以字符串形式返回的值包含特殊字符,并且在两次拆分后,我尝试将这些值传递给表!问题是,即使我尝试什么也没有发生,并且即使方法返回正确的值,我的表仍为空!问题可能出在html中,但是我找不到任何解决方案!任何想法都将受到欢迎!
我的代码:
<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>
<%}}%>
试试这个
<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>
<%
//int i = 0; do you need i? I don't understand original structure
if(Souli.hoho()!=null){
String[] lines = Souli.hoho().split("\\$");
for(String line: lines){
String[] kati = line.split("#");
%>
<tr>
<td><%=kati[0]%></td>
<td><%=kati[2]%></td>
<td><%=kati[1]%></td>
<td><%=kati[4]%></td>
<td><%=kati[3]%></td>
<td><%=kati[9]%></td>
<td><%=kati[5]%></td>
<td><%=kati[6]%></td>
</tr>
</table>
<%}}%>
但是我不确定kati[]
数组的索引。您可以从数据库中发布原始字符串示例吗(拆分之前)。另外(如果您仍在使用此版本),最好kati[]
在分割后检查数组中有多少个元素line
。是否有10个元素?
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句