我在JSP中有一个函数,当我调用它时出现错误,但我真的不知道原因。如果我将其粘贴到需要的地方,功能代码就可以正常工作。
JSP功能
<%!
public void console_table (java.io.PrintWriter out, int stackNr, String [] pstackNr) {
int c=0;
for(int i=0;i<stackNr;i++) {
out.println("<h3>Stiva "+(i+1)+"</h3>");
out.println("<div id='content_wrap'>");
for(int j=0;j<Integer.parseInt(pstackNr[i]);j++){
out.println("<div id='structure'>");
out.println("<div class='stack'>");
out.println("<table border='1'>");
out.println("<tr>");
out.println("<td><div id='empty"+c+"' class='empty'></div></td>");
out.println("<td><div id='empty"+c+"' class='empty'></div></td>");
out.println("<td><div id='empty"+c+"' class='empty'></div></td>");
out.println("<td><div id='empty"+c+"' class='empty'></div></td>");
out.println("</tr>");
out.println("</table>");
out.println("</div>");
out.println("</div>");
c++;
}
out.println("</div>");
}
}
%>
文件导入
<%@ include file="src/libs/console.lib.jsp" %>
通话功能
<%
int stackNr = 3;
String [] pstackNr = db_pstackNr.split(",");
console_table (out, stackNr, pstackNr);
%>
最佳答案
更改
public void console_table (java.io.PrintWriter out, int stackNr, String [] pstackNr)
至
public void console_table (javax.servlet.jsp.JspWriter out, int stackNr, String [] pstackNr) throws java.io.IOException
和
更改
console_table (out, stackNr, pstackNr);
try {
console_table (out, stackNr, pstackNr);
} catch (java.io.IOException e) {
//handle the exception
}
应该使它工作。基本上,问题在于'out'是JspWriter的一个实例,并且与PrintWriter不兼容。 (如果JspWriter是PrintWriter的子类,那很好,但是它们都是java.io.Writer的直接子类)
http://docs.oracle.com/javase/6/docs/api/java/io/PrintWriter.html
http://docs.oracle.com/javaee/6/api/javax/servlet/jsp/JspWriter.html
关于function - JSP错误: The method is not applicable for the arguments,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16821836/