JSP语法的xml表达

王朝java/jsp·作者佚名  2006-11-24
窄屏简体版  字體: |||超大  

大家总是不喜欢看到<%和%>在jsp页面上,其实我们可以使用比较优雅的xml方式来表达

1,隐含的注释

JSP语法:<%-- 内容 --%>

XML语法:无

2,变量或函数的声明

JSP语法:<%! declaration;[declaration;]+... %>

例如:

<%!

int i=0;int a,b,c;

Color red=new Color(255,0,0);

private static final String OK="ok";

public String getAnswer(){

return OK;

}

%>

XML语法:

<jsp:declaration>

declartion;[declaration;]+...

</jsp:declaration>

例如:

<jsp:declaration>

int i=0;int a,b,c;

Color red=new Color(255,0,0);

private static final String OK="ok";

public String getAnswer(){

return OK;

}

</jsp:declaration>

3,表达式

JSP语法:<%=expression%>

例如:

<%=Math.round(Math.random*100)%>

XML语法:

<jsp:expression>

expression

</jsp:expression>

例如:

<jsp:expression>

Math.round(Math.random*100)

</jsp:expression>

4,代码片断

JSP语法:<% your java code %>

例如:

<%

String username=request.getParameter("username").trim();

String password=request.getParameter("password").trim();

%>

XMl语法:

<jsp:scriptlet>

your java code

</jsp:scriptlet>

例如:

<jsp:scriptlet>

String username=request.getParameter("username").trim();

String password=request.getParameter("password").trim();

</jsp:scriptlet>

5,指令:include

JSP语法:<%@include file="relativeURL"%>

例如:<%@include file="static_head.html"%>

XML语法:<jsp:directive.include file="relativeURL"/>

例如:<jsp:directive.include file="static_head.html"/>

6,指令:page

JSP语法:<%@page attribtes%>

例如:<%@page import="java.util.HashMap"%>

XML语法:<jsp:directive.page attribute/>

例如:<jsp:directive.page import="java.util.HashMap"/>

7,指令:taglib

JSP语法:<%@taglib uri="UR

[1] [2] 下一页

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航