【问题标题】:JSP: How can I use expression tag in println in scriptlet tagJSP:如何在 scriptlet 标记中的 println 中使用表达式标记
【发布时间】:2021-02-28 07:33:18
【问题描述】:

标签在开发过程中变得复杂。

所以我无法确定这段代码是语法错误还是我犯了错误。

你能看看我贴的代码看看问题吗?

我以图片和文本格式上传了它。(我包括了图片格式,因为它会更直观。)

这是我要修复的代码(updateAction.jsp 中的 67 行):

"location.href = 'view.jsp?bbsID=<%=bbsID%>'"

这是图片格式:

enter image description here

enter image description here

这里是文本格式:

script.println("<script>");
//script.println("location.href = 'view.jsp?bbsID=<%=bbsID%>'"); -> my wrong code
//script.println("location.href = `please enter code here`");
script.println("</script>");

【问题讨论】:

  • 嗨,试试这个script.println("location.href = 'view.jsp?bbsID="+bbsID+"'");
  • @Andreas 我认为我不应该只上传图片,我可以将文本附加在一起。不过从现在开始,我只会附上文字:)谢谢你让我知道网站的规则。
  • @Swati 哦,这是工作!谢谢!
  • 什么是bbsID?请求属性?会话属性?还有什么?

标签: java html oop jsp servlets


【解决方案1】:

你应该这样做:

String bbsID = request.getParameter("bbsID");
script.println("location.href = 'view.jsp?bbsID="
        + URLEncoder.encode(bbsID, "UTF-8") + "'");

【讨论】:

    【解决方案2】:

    当您在"location.href = 'view.jsp?bbsID=&lt;%=bbsID%&gt;'" 中使用 %> 时,它可能已经关闭了代码中的开始 scriplet 标记

    &lt;% ................... ................... "location.href = 'view.jsp?bbsID=&lt;%=bbsID%&gt;'" ......... %&gt; 如果你使用System.out.println("location.href = 'view.jsp?bbsID=&lt;%=bbsID%"+"&gt;'"); ,虽然Swati已经提供的分辨率更好,但应该不会发生错误。

    【讨论】:

      猜你喜欢
      • 2012-12-19
      • 1970-01-01
      • 1970-01-01
      • 2011-03-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-07
      相关资源
      最近更新 更多