1. jstl中if-else实现
JSTL中<c:if>标签没有对应的else因此采用
<c:choose>
<c:when test=""> <!--如果 -->
</c:when>
<c:otherwise> <!--否则 -->
</c:otherwise>
</c:choose>
2. 在jsp页面如何获得url参数
当一个url过来时,如:http://localhost:8080/SpringMVC/hello.jsp?name=john,在hello.jsp页面,我们可以这样得到name的值,代码如下:
<% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; String name = request.getParameter("name");//用request得到 %>
然后在<body>Hi,<%=name%></body>中显示。
也可以在body中直接用${}得到,因为当使用jstl时,url请求参数被放置到隐含对象param中。所以可以这样写:
<body>hello:${param.name}</body>
依据此逻辑,在使用jquery时,也可以用同样的方法得到,如:
$(function(){ alert(${param.name}); });
当然,<%=name%>不能防御XSS攻击,可以采用JSTL(JSP Standard Tag Library)开放源代码的JSP标签库。
Hi,<c:out value="${name}"/>
3. 块元素覆盖的问题
z-index默认是0,要想元素显示在其他元素之上,此值应大于其他块元素的值。