2013-11-26 9 views
2

我需要一個值的表中一個jsp分配給特定的細胞,並創造了ID爲「表1」中的表,表中的值分配給小區使用這些命令將值單元格表所示:使用小區ID

<%@ page import="java.io.*"%> 
<html> 
<head> 
</head> 
<body> 
<table id="table1" border = "1"> 

<% 
var table = document.getElementById("table1"); 
table.rows[1].cells[2].innerHTML = "UP"; 
%> 

<tr> 
<th></th> 
<th>DEV1</th> 
<th>DEV2</th> 
<th>SIT1</th> 
<th>SIT2</th> 
<th>UAT</th> 
<th>NFT</th> 
</tr> 

<tr> 
<td>SFG Process</td> 
<td>row 1, cell 1</td> 
<td>row 1, cell 2</td> 
<td>row 1, cell 3</td> 
<td>row 1, cell 4</td> 
<td>row 1, cell 5</td> 
<td>row 1, cell 6</td> 
</tr> 

<tr> 
<td>SCC Process</td> 
<td>row 2, cell 1</td> 
<td>row 2, cell 2</td> 
<td>row 2, cell 3</td> 
<td>row 2, cell 4</td> 
<td>row 2, cell 5</td> 
<td>row 2, cell 6</td> 
</tr> 

</table> 
</body> 
</html> 

但是Tomcat的是給thsi錯誤:

org.apache.jasper.JasperException: Unable to compile class for JSP: 

An error occurred at line: 9 in the jsp file: /emt/xyz.jsp 
var cannot be resolved to a type 
6: <table id="table1" border = "1"> 
7: 
8: <% 
9: var table = document.getElementById("table1"); 
10: table.rows[1].cells[2].innerHTML = "UP"; 
11: %> 
12: 


An error occurred at line: 9 in the jsp file: /emt/xyz.jsp 
document cannot be resolved 
6: <table id="table1" border = "1"> 
7: 
8: <% 
9: var table = document.getElementById("table1"); 
10: table.rows[1].cells[2].innerHTML = "UP"; 
11: %> 
12: 


Stacktrace: 
    org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92) 
    org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330) 
    org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:443) 
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:356) 
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:334) 
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:321) 
    org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:592) 
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:328) 
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313) 
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260) 
    javax.servlet.http.HttpServlet.service(HttpServlet.java:723) 
+0

向我們展示完整的代碼。 –

+1

看來你正在使用scriplet中的JavaScipt。您是否意識到scriptlet是在服務器端執行的Java代碼片段,JavaScript是發送到瀏覽器並由瀏覽器執行的代碼? –

+0

我最近開始編碼和使用JavaScript,所以答案是否定的,我不知道。你能指導我需要做什麼嗎? – cherry2891

回答

2
<% 
var table = document.getElementById("table1"); 
table.rows[1].cells[2].innerHTML = "UP"; 
%> 

你正在寫的jsp裏面的java腳本代碼,從而編譯失敗。

你只是刪除代碼,而<script>標籤

<SCRIPT type="text/javascript"> 
    var table = document.getElementById("table1"); 
    table.rows[1].cells[2].innerHTML = "UP"; 
</SCRIPT> 

See this link爲完整的參考和示例之間加太多。

+0

謝謝,這是現在工作:) – cherry2891

+0

@ cherry2891很高興幫助你:) –

0

嘗試使用JavaScript來改變innerHTML的!

var table = document.getElementById("table1"); 
table.rows[1].cells[2].innerHTML = "XYZ"; 
+0

感謝您的回答,但仍然收到相同的錯誤。請參閱代碼和錯誤附 – cherry2891

+0

不知道你沒有使用

  • 11. 從CellInfoLte獲取位置區號和小區ID
  • 12. 重用小區... :(
  • 13. 使用ID和onClick之間的區別
  • 14. 使用畫布的ID調整大小?
  • 15. 如何利用區ID
  • 16. 使用細胞旁另一個小區
  • 17. 不區分大小寫SELECT使用「IN」
  • 18. 使用VB.net降低USB分區大小
  • 19. 使用VBA最小化Office功能區?
  • 20. 使用。除不區分大小寫C#
  • 21. 時區加入到使用小時nsdateformatter
  • 22. 使用div調整文本區大小
  • 23. 硒表定位小區使用CSS
  • 24. 區分ID的
  • 25. 使區分大小寫不敏感的區分大小寫表
  • 26. 使用matplotlib在不同小區(無子小區)之間鏈接軸
  • 27. 如何使用小部件ID更新小部件?
  • 28. 使用XML功能區的動態功能區按鈕大小
  • 29. 如果使用YUI 2.8,是否可以避免使用區分大小寫的ID?
  • 30. 當使用「請求」時,「此小部件ID已被使用」