当out.write已经在scriptlet标签中时,如何out.write scriptlet标签?
<% if (answerList.size() > 2){
int toPrint = answerList.size() - 2;
int init = 2;
for (int x = 0; x < toPrint; x++){
out.write("<td width='30%' class='label' nowrap='nowrap'><label></label></td>");
out.write("<td><input type='checkbox' name='to_delete" + (init+1) + "' id='to_delete" + (init+1) + "' value='to_delete'>       ");
out.write("<input type='text' name='answer' id='answer' class='mlselect' maxlength='200' size='90' value='<%=((SurveyAnswerBean)answerList.get(answerList.size()-"+(init+1) +")).getAnswerText()%>'>   ");
}
System.out.println("Answer List more than 2");
System.out.println("To print: " + toPrint);
}%>
我试过但它有标签错误,任何帮助将不胜感激!
答案 0 :(得分:1)
答案是你不能嵌套scriplets标签,这样做也没有意义(因为你无法在客户端评估服务器端变量)侧)。
你应该替换:
"...value='<%=((SurveyAnswerBean)answerList.get(answerList.size()-"+(init+1) +")).getAnswerText()%>'...
使用:
"...value='" + ((SurveyAnswerBean)answerList.get(answerList.size()-(init+1))).getAnswerText() +"'...