如何编写 jstl 而不是 scriptlet?
<%
UserDetailsVO objUserDetailsVO = null;
ArrayList arlUserDetailsVO = (ArrayList)request.getAttribute("LSTUSERSDETAILS");
String nonBifFlag = "";
if(arlUserDetailsVO !=null){
Iterator it = arlUserDetailsVO.iterator();
String urlProfile="";
while(it.hasNext()){
objUserDetailsVO = (UserDetailsVO)it.next();
urlProfile = "UserProfile.htm?userID="+objUserDetailsVO.getLogin_Ident()+"&internalID=111"+objUserDetailsVO.getInternalId();
%>
<%
UserDetailsVO objUserDetailsVO = null;
ArrayList arlUserDetailsVO = (ArrayList)request.getAttribute("LSTUSERSDETAILS");
String nonBifFlag = "";
if(arlUserDetailsVO !=null){
Iterator it = arlUserDetailsVO.iterator();
String urlProfile="";
while(it.hasNext()){
objUserDetailsVO = (UserDetailsVO)it.next();
urlProfile = "UserProfile.htm?userID="+objUserDetailsVO.getLogin_Ident()+"&internalID=111"+objUserDetailsVO.getInternalId();
%>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
确保您拥有 JSTL 位于您的类路径中(即您的 Web 项目的
WEB-INF/lib
文件夹)。您将需要在 jsp 页面的顶部:代码的字面翻译如下所示:
尽管如此,考虑到您实际上并不需要将页面/请求属性设置为
null
因为它们是已经null
,您可能可以将其简化为:请注意,通过使用
构造您的 url,您的 url 参数现在将被正确编码,因为它们没有被编码在您的 java 代码片段中。Make sure you have
jstl.jar
andstandard.jar
from the JSTL are in your classpath (ie. your web project'sWEB-INF/lib
folder). A the top of your jsp page you will need:A literal translation of your code would look like this:
Although, considering tha you don't really need to set page/request attributes to
null
since they are alreadynull
, you could probably pare it down to this:Note that by using
<c:url>
to construct your url, your url params will now be correctly encoded, where as they are not being encoded in your java code snippet.尝试核心标签以及请求的绑定等,例如
、
、
...这是一个简短教程(或者如果可以的话阅读德语:德语教程/参考)。
Try the core tags as well as bindings for the request etc., e.g.
<c:forEach>
,<c:out>
,<c:if>
...Here's a short tutorial (or if you can read German: a German tutorial/reference).