开发者

Using an if statement to decided whether or not to show a table on a jsp page

I have a parameter of user that I am setting equal to -1 if this param is not given. I only want to show the table if the parameter is fulfilled ( for instance if user = 1 ).

ex:

if(user >= 1){
<table>
<tr>
.....
</tr>
</table>
}

Is this possible, or how would you recommend doing this?


I would recommend you to use JSTL. <c:if> tag, also to set the parameter as attribute in request to use it on jsp


Request parameters are as a Map<String, String> available by ${param} in EL. So a request parameter with the name user is available by ${param.user}.

JSTL provides the core tags like <c:if> to control the flow in the page.

So, 1 + 1 = ...

<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
...
<c:if test="${param.user > 0}">
    <table>
        ...
    </table>
</c:if>


<% if(user >= 1){ %>

some html

<% } %>


You shouldn't try to intermix Java scriptlets inside JSP. Use JSTL instead. You would have to import the core library <%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> and include jstl.jar standard.jar in your classpath which can be found on the Apache Site

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜