日期:2014-05-20  浏览次数:20723 次

jsp页面的小问题,答完即刻送分
jsp页面的问题: getWebiReports(infoStore)是一个字符串,中间有“\t”类型的空格,以这个空格为分界点把这个字符串分成i个,
如何做,下面的程序在“document.write("<%= title[i]%>") ”提示错误,和其中的i有关,如何获得这个i

<body> 
   
  <div id="rotate">
  <ul>  
  <% out.println(getWebiReports(infoStore)); %>
  <% out.println(getWebiReports(infoStore).split("\t").length); %>
  <% String[] title=getWebiReports(infoStore).split("\t");%>
   
   
  <script type="text/javascript">  
  for (i = 0; i < <% out.println(getWebiReports(infoStore).split("\t").length); %>; i++)
  {  
  document.write("<li>")  
  document.write("<a href=http://localhost:8080/report/report3.jsp target=open>")  
  document.write("<span>")  
  document.write("<%= title[i]%>") ///////报错行///////
  document.write("</span></a></li>") 
  }  
  </script> 
  </ul>
   
   
  </div>
  </body>

------解决方案--------------------
1.不用再用javascript的document.write写页面了。直接通过for循环在JSP直接写就Ok了。
2.代码大致如下:
HTML code

<body> 
      
      <div id="rotate"> 
            <ul>        
        <% out.println(getWebiReports(infoStore)); %> 
        <% out.println(getWebiReports(infoStore).split("\t").length); %> 
        <% String[] title=getWebiReports(infoStore).split("\t");%> 
        <%
            for (i = 0; i<title.length; i++) 
            {    
        %>            
                <li>
                <a href=http://localhost:8080/report/report3.jsp target=open>")
                <span> 
                 <%= title[i]%>
                </span> </a> </li>
         <%}%>       
                </ul> 
            
          
        </div> 
    </body>