博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
JSP
阅读量:4487 次
发布时间:2019-06-08

本文共 1729 字,大约阅读时间需要 5 分钟。

1.各个指令的含义

<%@page指令

contentType = "text/html"; charset = UTF-8

相当于response.setContentType("text/html; charset = UTF-8");

上面通知浏览器以UTF-8进行中文编码

 

pageEncoding = “UTF-8”

如果jsp文件中出现了中文,这些中文使用UTF-8进行编码

 

import = “java.util.*”

导入其他类,如果导入多个类,彼此用,逗号隔开,像这样import  = "java.util.*,java.sql.*"

 

二、执行过程

1.把hello.jsp转译为hello_jsp.java

2.hello_jsp.java是一个servlet

3.把hello_jsp.java编译为hello_jsp.class

4.执行hello_jsp,生成html

5.通过http协议把html响应返回给浏览器

三、页面元素总结

1.静态内容

  就是html,css,javascript等内容

2.指令

  以<%@开始 %>结尾,比如<%@page  import = "java.util.*" %>

3.表达式<%= %>

  用于输出一段html

4.scriptlet

  在<% %>之间,可以写任何java代码

5.声明

在<%!%>之间可以声明字段或者方法。但是不建议这么做

6.动作

  <jsp:include page = "Filename">在jsp页面中包含另一个页面

7.注释<%--   --%>

不同于html的注释<!-- -->通过jsp的注释,浏览器也看不到相应的代码,相当于在servlet中注释掉了

 

四、循环

<%

  List<String> words = new ArrayList<String>();

  words.add("today");

  words.add("is");

  words.add("a");

  words.add("great");

  words.add("day");

%>

<table width ="200px" align = "center" border = "1" cellspace = "0">

<%for(String word : words)  {%>

<tr>

  <td><%=word%></td>

</tr>

<%}%>

</table>

五、include

1.首先准备一个footer.jsp

<hr>

<p style = "text-align:center">copyright@2016

</p>

2.通过指令

<%@include file = "footer.jsp" %>在其他jsp文件中包含footer.jsp页面

 

3.通过动作

<jsp: include page = "footer.jsp"/>

在hello.jsp中包含该页面

 

区别:动作的方式会产生一个footer_jsp.java独立存在

hello_jsp.java会在服务器访问footer_jsp.java,然后把返回的结果,嵌入到响应中

例子:

hello.jsp中:

<%@page contentType="text/html; charset=UTF-8"

pageEncoding="UTF-8" import="java.util.*"%>
你好 JSP
<%=new Date().toLocaleString()%>
<jsp:include page="footer.jsp">

<jsp:param name = "year" value = "2017"/>

</jsp:include>

 

在footer.jsp中

<hr>

  <p style = "text-align:center">copyright@<%= request.getParameter("year")%>

</p>

 

转载于:https://www.cnblogs.com/zxj-262410/p/8545547.html

你可能感兴趣的文章
数据表格 - DataGrid - 行编辑
查看>>
申请TexturePacker 或 PhysicsEditor free licenses
查看>>
kafka启动报错&问题解决
查看>>
nginx反向代理下没有获取到正确的clientIP问题发散
查看>>
python周报第一周
查看>>
IBM MQ 创建以及常见问题集锦
查看>>
Office文件的奥秘——.NET平台下不借助Office实现Word、Powerpoint等文件的解析(1)
查看>>
SQL Server 服务器磁盘测试之SQLIO篇(一)
查看>>
sun.misc.Unsafe 详解
查看>>
食堂排队问题的一个实现
查看>>
Git 回滚代码的正确姿势
查看>>
构造函数、析构函数、虚析构函数、纯虚析构函数要点
查看>>
Python批量获取京东商品列表信息
查看>>
2017.7.10 C组总结
查看>>
SourceTree下载 及使用
查看>>
MyEclipse下安装FatJar打包工具
查看>>
什么是域名-视频讲解?
查看>>
大道至简第六章-从编程到工程
查看>>
单元测试——隔离神器:mockito
查看>>
[Web Tools] 实用的Web开发工具
查看>>