试图嵌入在jsp scriplet标签中使用html

时间:2016-10-11 11:14:38

标签: java html jsp

我正在jsp页面中检索会话属性,我想如果会话为null,则让它显示登录屏幕的登录按钮。这是我的尝试,但我遇到了在jsp scriplet标签中使用html的挑战,如图所示

<span style="float:right; top:-10px;  position: relative; color:#000; font-size: 80%">
                 <% if(session.getAttribute("email") != null)
                    {
                                      out.println(session.getAttribute("email"));
                    }else{
            <a href="/login-admin" class="btn btn-default"style="color:#4b4f54; font-weight:bold; border:1px solid #4b4f54;">Log In</a> 
                    }
                 %>
            </span>

是否可以在jsp的scriplet标签中使用html

3 个答案:

答案 0 :(得分:1)

在必要时打开/关闭scriplet ...... ArrayAdapter 在你的情况下:

<% if {%> htmlcode <%}>

答案 1 :(得分:1)

你可以关闭jsp标签然后插入html打开jsp标签再看看我的例子。

<TABLE BORDER=2>
<%
for ( int i = 0; i < n; i++ ) {
    %>
    <TR>
    <TD>Number</TD>
    <TD><%= i+1 %></TD>
    </TR>
    <%
}
%>
</TABLE>

和:

<%
if ( hello ) {
    %>
    <p>This actually works?</p>
    <%
} else {
    %>
    <p>This is amazing </P>
    <%
}
%>

在你的情况下:

<span style="float:right; top:-10px;  position: relative; color:#000; font-size: 80%">
             <% if(session.getAttribute("email") != null)
                {
                                  out.println(session.getAttribute("email"));
                }else{%>
        <a href="/login-admin" class="btn btn-default"style="color:#4b4f54; font-weight:bold; border:1px solid #4b4f54;">Log In</a> 
                <% }
             %>
        </span>

答案 2 :(得分:0)

在添加html代码之前,您需要关闭scriplet ...尝试将代码更改为此。

.Rectangle()