一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

jsp include两种调用形式详细

时间:2022-06-29 02:39:42 编辑:袖梨 来源:一聚教程网

include有两种形式,分别是Include指令:和include动作:jsp教程:include page="" flush="true"/>

include调用文件

,是将被引入的JSP与原JSP融合到一起,而这个融合过程是在翻译阶段进行的

index.jsp


Flavors


Our most popular flavors are:

Try them all!

flavor_list.html


  1. Chocolate

  2. Strawberry

  3. Vanilla


常当应用程序中所有的页面的某些部分(例如标题、页脚和导航栏)都相同的时候,我们就可以考虑用include。具体在哪些时候用,哪些时候用。这种形式

include一个页面的地址


Flavors


Our most popular flavors are:

Try them all!


根据用户提交的参数请求,我们调用不用的文件
实例

// Diameter of the earth in kilometers

int distance = 12756;
%>

Diameter of the Earth in SI (Metric) Units





Diameter of the Earth in U.S. Customary Units







ShowDiameter.jsp


String dist = request.getParameter("dist");
if (dist == null)
throw new ServletException
("No distance parameter specified");

int kilometers = Integer.parseInt(dist);
double miles = kilometers / 1.609344;

String units = request.getParameter("units");
if (units == null)
throw new ServletException
("No units parameter specified");

if (units.equals("SI")) {
%> Diameter = km }
else {
%> Diameter = miles }
%>

热门栏目