如何将这个简单的 scriptlet 转换为 JSTL?
How do I convert this simple scriptlet to JSTL?
我正在尝试将以下 scriptlet 转换为 JSTL
<%
String req = request.getParameter("loginfailed");
if(req != null)
{
if(req.equals("true"))
{%>
<h4 id="loginerrormessage">Invalid email address or password.</h4>
<%}
}
%>
这个 scriptlet 工作得很好,但我现在正在尝试将它转换为 JSTL,我是新手。这是我使用 JSTL 重新创建逻辑的最佳尝试。
<c:set var="req" value="${request.getParameter(\"loginfailed\")}"/>
<c:if test="${ req!=null }">
<c:if test="${ req.equals(\"true\") }">
<h4 id="loginerrormessage">Invalid email address or password.</h4>
</c:if>
</c:if>
当我用上面编写的 JSTL 替换 scriptlet 时,没有任何崩溃,但我不再看到 "Invalid email address or password.",而我本应使用 scriptlet 看到它。我不确定我在这里做错了什么。
是范围问题吗?我认为默认页面范围适用于 c:set。这可能与我在 JSTL 中使用转义引号有关吗?
只需使用
<c:if test="${ param.loginfailed eq 'true' }">
<h4 id="loginerrormessage">Invalid email address or password.</h4>
</c:if>
此处 param
是隐式 JSP 对象,它使您可以访问请求参数。
我正在尝试将以下 scriptlet 转换为 JSTL
<%
String req = request.getParameter("loginfailed");
if(req != null)
{
if(req.equals("true"))
{%>
<h4 id="loginerrormessage">Invalid email address or password.</h4>
<%}
}
%>
这个 scriptlet 工作得很好,但我现在正在尝试将它转换为 JSTL,我是新手。这是我使用 JSTL 重新创建逻辑的最佳尝试。
<c:set var="req" value="${request.getParameter(\"loginfailed\")}"/>
<c:if test="${ req!=null }">
<c:if test="${ req.equals(\"true\") }">
<h4 id="loginerrormessage">Invalid email address or password.</h4>
</c:if>
</c:if>
当我用上面编写的 JSTL 替换 scriptlet 时,没有任何崩溃,但我不再看到 "Invalid email address or password.",而我本应使用 scriptlet 看到它。我不确定我在这里做错了什么。
是范围问题吗?我认为默认页面范围适用于 c:set。这可能与我在 JSTL 中使用转义引号有关吗?
只需使用
<c:if test="${ param.loginfailed eq 'true' }">
<h4 id="loginerrormessage">Invalid email address or password.</h4>
</c:if>
此处 param
是隐式 JSP 对象,它使您可以访问请求参数。