gpt4 book ai didi

java - 使用单元格 ID 为表格中的单元格赋值

转载 作者:行者123 更新时间:2023-11-28 00:03:09 28 4
gpt4 key购买 nike

我需要为 jsp 中表格中的特定单元格分配一个值,并创建了一个 ID 为“table1”的表格:

现在使用这些命令为该表中的单元格赋值:

<%@ 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 给出了这个错误:

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)

最佳答案

<%
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以获得完整的引用和示例。

关于java - 使用单元格 ID 为表格中的单元格赋值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20217183/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com