我在工作中维护一个内部应用程序,我在jsp页面的javascript函数中面临随机中断问题,因为来自未知来源的空白。该应用程序在tomcat v8.5.30和jre 1.8.0_191上运行。
jsp页面看起来正确,tomcat的编译也正确。当tomcat将页面提供给用户时,不来自代码的空白会导致脚本块不加载或html标记中断(例如:“”、“”或“”)。这个问题似乎一直在发生,但空格似乎与输出的大小有关,输出长度的变化似乎会移动空格(两次出现之间大约7600个字符),并随机打断键标记的脚本块,有时是css或表格式。
我试图用wireshark检查响应,怀疑在固定帧长的传输中存在故障,但通过缝合传输的帧,我找不到任何错误。我搜索了空白、随机、tomcat的排列,但我能找到的只是tomcat的trimwhitespace指令(web.xml和jsp中的特定页面)和trimwhitespace过滤器(https://balusc.omnifaces.org/2007/12/whitespacefilter.html).
我试过这个过滤器,它做到了它声称的,但这与我面临的问题不符。
以下是阻止用户的最新消息:
编辑:添加错误截图错误截图
proreleaseedit.jsp?doaction=createrelease:673未捕获语法错误:无效或意外标记
function addPrerequisiteRow(releaseId, releaseCode, releaseTitle, releaseDate, releaseVersion, releaseEdition){
var rowId = generatePrqNextRowId();
var tbody = document.getElementById("prqTable").getElementsByTagName("TBODY")[0];
var row = document.createElement("TR");
row.id = "prqrow_" + rowId;
// delete
var td1 = document.createElement("TD");
td1.title = "Delete";
td1.className = "ColCtr";
td1.innerHTML = "<input type=\"c
heckbox\" name=\"prqcheckbox_" + rowId + "\" id=\"prqcheckbox_" + rowId + "\" value=\"true\" onClick=\"selectRow(this)\" >"
+"<input type=\"hidden\" name=\"prq_id_" + rowId + "\" id=\"prq_id_" + rowId + "\" value=\"" + releaseId + "\">"
+"<input type=\"hidden\" name=\"prq_idx_" + rowId + "\" id=\"prq_idx_" + rowId + "\" value=\"" + rowId + "\">";
// move
proreleaseedit.jsp?doaction=createrelease:1121未捕获引用错误:未定义nline
</body>
<script>
CKEDITOR.disableAutoInline = true;
CKEDITOR.inline('r_comment');
CKEDITOR.i
nline('r_description');
</script>
如果我尝试在表单末尾运行submit函数,所有这些错误都会阻止注册该函数:proreleaseedit.jsp?doaction=createrelease:1078 uncaught referenceerror:dosave未定义
我发现通过在脚本块中围绕每个函数可以避免一些错误,但我知道强烈建议不要这样做。
这是jsp文件中编写的代码:
function addPrerequisiteRow(releaseId, releaseCode, releaseTitle, releaseDate, releaseVersion, releaseEdition){
var rowId = generatePrqNextRowId();
var tbody = document.getElementById("prqTable").getElementsByTagName("TBODY")[0];
var row = document.createElement("TR");
row.id = "prqrow_" + rowId;
// delete
var td1 = document.createElement("TD");
td1.title = "Delete";
td1.className = "ColCtr";
td1.innerHTML = "<input type=\"checkbox\" name=\"prqcheckbox_" + rowId + "\" id=\"prqcheckbox_" + rowId + "\" value=\"true\" onClick=\"selectRow(this)\" >"
+"<input type=\"hidden\" name=\"<%= ReleaseWebImpl.PRE_REQUISITE_ID_F%>" + rowId + "\" id=\"<%= ReleaseWebImpl.PRE_REQUISITE_ID_F%>" + rowId + "\" value=\"" + releaseId + "\">"
+"<input type=\"hidden\" name=\"<%= ReleaseWebImpl.PRE_REQUISITE_IDX_F%>" + rowId + "\" id=\"<%= ReleaseWebImpl.PRE_REQUISITE_IDX_F%>" + rowId + "\" value=\"" + rowId + "\">";
// move
var td2 = document.createElement("TD");
td2.title = "Move";
td2.className = "ColCtr";
td2.innerHTML = "<a href=\"javascript:moveUpRow('" + row.id + "')\"><span class=LogoPrecSuiv title=\"Move Upd\">5</span></a>"
+"<a href=\"javascript:moveDownRow('" + row.id + "')\"><span class=LogoPrecSuiv title=\"Move Down\">6</span></a>";
// code
var td3 = document.createElement("TD");
td3.className = "ColGch";
td3.innerHTML = releaseCode;
// title
var td4 = document.createElement("TD");
td4.className = "ColGch";
td4.innerHTML = releaseTitle;
// date
var td5 = document.createElement("TD");
td5.className = "ColGch";
td5.innerHTML = releaseDate;
// version
var td6 = document.createElement("TD");
td6.className = "ColGch";
td6.innerHTML = releaseVersion;
// edition
var td7 = document.createElement("TD");
td7.className = "ColGch";
td7.innerHTML = releaseEdition;
row.appendChild(td1);
row.appendChild(td2);
row.appendChild(td3);
row.appendChild(td4);
row.appendChild(td5);
row.appendChild(td6);
row.appendChild(td7);
tbody.appendChild(row);
//
};
和
</body>
<script>
CKEDITOR.disableAutoInline = true;
CKEDITOR.inline('<%= ReleaseWebImpl.REL_COMMENT_F%>');
CKEDITOR.inline('<%= ReleaseWebImpl.REL_DESCRIPTION_F%>');
<%
list = release.getDetails().iterator();
itemIndex = 0;
while (list.hasNext()) {
ReleaseDetail item = (ReleaseDetail)list.next();
itemIndex++;
%>
CKEDITOR.inline('<%= ReleaseWebImpl.DET_TITLE_F%><%= itemIndex%>');
CKEDITOR.inline('<%= ReleaseWebImpl.DET_DESCRIPTION_F%><%= itemIndex%>');
<%}//end of detailList %>
</script>
jsp编译为:
out.write("\tfunction addPrerequisiteRow(releaseId, releaseCode, releaseTitle, releaseDate, releaseVersion, releaseEdition){\r\n");
out.write("\t\tvar rowId = generatePrqNextRowId();\r\n");
out.write("\t\tvar tbody = document.getElementById(\"prqTable\").getElementsByTagName(\"TBODY\")[0];\r\n");
out.write("\t\tvar row = document.createElement(\"TR\");\r\n");
out.write("\t\trow.id = \"prqrow_\" + rowId;\r\n");
out.write("\r\n");
out.write("\t\t// delete\r\n");
out.write("\t\tvar td1 = document.createElement(\"TD\");\r\n");
out.write("\t\ttd1.title = \"Delete\";\r\n");
out.write("\t\ttd1.className = \"ColCtr\";\r\n");
out.write("\t\ttd1.innerHTML = \"<input type=\\\"checkbox\\\" name=\\\"prqcheckbox_\" + rowId + \"\\\" id=\\\"prqcheckbox_\" + rowId + \"\\\" value=\\\"true\\\" onClick=\\\"selectRow(this)\\\" >\"\r\n");
out.write("\t\t\t\t\t+\"<input type=\\\"hidden\\\" name=\\\"");
out.print( ReleaseWebImpl.PRE_REQUISITE_ID_F);
out.write("\" + rowId + \"\\\" id=\\\"");
out.print( ReleaseWebImpl.PRE_REQUISITE_ID_F);
out.write("\" + rowId + \"\\\" value=\\\"\" + releaseId + \"\\\">\"\r\n");
out.write("\t\t\t\t\t+\"<input type=\\\"hidden\\\" name=\\\"");
out.print( ReleaseWebImpl.PRE_REQUISITE_IDX_F);
out.write("\" + rowId + \"\\\" id=\\\"");
out.print( ReleaseWebImpl.PRE_REQUISITE_IDX_F);
out.write("\" + rowId + \"\\\" value=\\\"\" + rowId + \"\\\">\";\t\t\t\t\t\r\n");
out.write("\r\n");
和
out.write("\t<script>\r\n");
out.write("\t\tCKEDITOR.disableAutoInline = true;\r\n");
out.write("\t\tCKEDITOR.inline('");
out.print( ReleaseWebImpl.REL_COMMENT_F);
out.write("');\r\n");
out.write("\t\tCKEDITOR.inline('");
out.print( ReleaseWebImpl.REL_DESCRIPTION_F);
out.write("');\r\n");
out.write("\t");
list = release.getDetails().iterator();
itemIndex = 0;
while (list.hasNext()) {
ReleaseDetail item = (ReleaseDetail)list.next();
itemIndex++;
out.write("\r\n");
out.write("\t\t\tCKEDITOR.inline('");
out.print( ReleaseWebImpl.DET_TITLE_F);
out.print( itemIndex);
out.write("');\r\n");
out.write("\t\t\tCKEDITOR.inline('");
out.print( ReleaseWebImpl.DET_DESCRIPTION_F);
out.print( itemIndex);
out.write("');\r\n");
out.write("\t");
}//end of detailList
out.write("\r\n");
out.write("\t</script>\r\n");
1条答案
按热度按时间ruarlubt1#
在我看来,它就是您声称在jsp中的函数
不会在服务器端解释,而是逐字发送到客户端。如果这是要在浏览器中执行的javascript代码,那么它没有任何问题。但是请注意,您在这些javascript行开头看到的空白实际上来自jsp。毕竟,您使用了WhiteSpace来格式化代码,这只是被保留了下来。
所以,如果您不喜欢这个空白,请从jsp中删除它,它就会消失。