网站上传都传些什么文件网站建设启动资金预算
web/
2025/10/2 9:12:15/
文章来源:
网站上传都传些什么文件,网站建设启动资金预算,住房建设部官方网站公示公告,wordpress自适应不换行一、EL表达式
1.1.特点 是一个由java开发的工具包 用于从特定域对象中读取并写入到响应体开发任务#xff0c;不能向域对象中写入。 EL工具包自动存在Tomcat的lib中#xff08;el-api.jar#xff09;#xff0c;开发是可以直接使用#xff0c;无需其他额外的包。 标准…一、EL表达式
1.1.特点 是一个由java开发的工具包 用于从特定域对象中读取并写入到响应体开发任务不能向域对象中写入。 EL工具包自动存在Tomcat的lib中el-api.jar开发是可以直接使用无需其他额外的包。 标准格式 ${域对象别名.。关键字} 到指定的域中获取相应关键字的内容并将其写入到响应体。
1.2.域对象 注使用时可以省略域对象别名
默认查找顺序 pageScope - requestScope - sessionScope - applicationScope
最好只在pageScope中省略 对应案例 % page contentTypetext/html;charsetUTF-8 languagejava %
html
headtitlejsp/title
/head
body%application.setAttribute(name,applcation);session.setAttribute(name,session);request.setAttribute(name,request);pageContext.setAttribute(name,pageContext);%br--------------使用java语言----------------brapplication中的值% application.getAttribute(name)%brsession中的值% session.getAttribute(name)%brrequest中的值% request.getAttribute(name)%brpageContext中的值% pageContext.getAttribute(name)%br
br--------------使用EL表达式----------------brapplication中的值${applicationScope.name}brsession中的值${sessionScope.name}brrequest中的值${requestScope.name}brpageContext中的值${pageScope.name}br
br--------------使用EL表达式省略域对象----------------brapplication中的值${name}br
/body
/html 1.3.支持的运算
1数学运算
2比较运算 gt lt ge le eq ! !
3逻辑预算 || 对应案例 % page importcom.sun.org.apache.xpath.internal.operations.Bool %
% page contentTypetext/html;charsetUTF-8 languagejava %
html
headtitleEL运算/title
/head
body
%request.setAttribute(num1,12);request.setAttribute(num2,14);
application.setAttribute(flag1,true);application.setAttribute(flag2,false);
%
br---------------使用java语言-------------------br
%String num1 (String)request.getAttribute(num1);String num2 (String)request.getAttribute(num2);int num3 Integer.parseInt(num1)Integer.parseInt(num2);
boolean flag1 (Boolean)application.getAttribute(flag1);boolean flag2 (Boolean)application.getAttribute(flag2);boolean flag3 flag1 flag2;
//输出方式一out.write(Boolean.toString(flag3));
%
!-- 输出方式二 --
h1%num3%/h1
br---------------使用EL表达式-------------------br
h1${ requestScope.num1 requestScope.num2 }/h1
h1${ requestScope.num1 requestScope.num2 }/h1
h1${ applicationScope.flag1 applicationScope.flag2 }/h1
/body
/html
1.4.其他的内置对象
1param 使用 ${param.请求参数名} 从请求参数中获取参数内容
2paramValues 使用 ${ paramValues.请求参数名 } 从请求参数中获取多个值以数组的形式
3initParam 使用 ${ initParam.参数名 } 获取初始化参数
% page importcom.sun.org.apache.xpath.internal.operations.Bool %
% page contentTypetext/html;charsetUTF-8 languagejava %
html
headtitle其他内置对象/title
/head
bodyurl:...?usernamezhangsanpasswordadminbrurl中的参数用户名${param.username} --- 密码${param.password}br-------------------------------------------brurl:...?usernamezhangsanusernamelisiurl中的参数用户1${paramValues.username[0]} ---用户2${paramValues.username[1]}br-------------------------------------------br
!--在web.xml中添加启动参数context-paramparam-namedriver/param-nameparam-valuecom.mysql.jdbc.Driver/param-value/context-param--获取启动参数${initParam.driver}/body
/html
1.5.EL表达式的缺陷
1只能读取域对象中的值不能写入
2不支持if判断和控制语句 二、 JSTL标签工具类
2.1.基本介绍
1 JSP Standrad Tag Lib jsp标准标签库
2 是sun公司提供
3 组成 4使用原因使用简单且在JSP编程当中要求尽量不出现java代码。
2.2.使用方式
1导入依赖的jar包 jstl.jar standard.jar
2在jsp中引入JSTL的core包依赖约束
% taglib prefixc urihttp://java.sun.com/jsp/jstl/core %
2.3.重要标签的使用
2.3.1.c: set
在JSP文件上设置域对象中的共享数据
% page importcom.sun.org.apache.xpath.internal.operations.Bool %
% page contentTypetext/html;charsetUTF-8 languagejava %
% taglib prefixc urihttp://java.sun.com/jsp/jstl/core %
html
headtitle c:set /title
/head
body
%--相当于%request.setAttribute(name,zhangsan);%--%c:set scoperequest varname valuezhangsan/通过JSTL添加的作用域的值${requestScope.name} brc:set scopeapplication varname valuelisi/通过JSTL添加的作用域的值${applicationScope.name} brc:set scopesession varname valuewangwu/通过JSTL添加的作用域的值${sessionScope.name} brc:set scopepage varname valuezhaoliu/通过JSTL添加的作用域的值${pageScope.name} br
/body
/html
2.3.2.c: if
控制哪些内容能够输出到响应体
% page importcom.sun.org.apache.xpath.internal.operations.Bool %
% page contentTypetext/html;charsetUTF-8 languagejava %
% taglib prefixc urihttp://java.sun.com/jsp/jstl/core %
html
headtitle c:if /title
/headc:set scopepage varage value20/br---------------使用java语言------------------br%if(Integer.parseInt((String)pageContext.getAttribute(age)) 18){%输入欢迎光临% }else{ %输入未满十八禁止入内% } %br---------------使用JSTL标签------------------brc:if test${age ge 18}输入欢迎光临/c:ifc:if test${age lt 18}输入未满十八禁止入内/c:if
/body
/html
2.3.3.c: choose
在jsp中进行多分支判断决定哪个内容写入响应体
% page importcom.sun.org.apache.xpath.internal.operations.Bool %
% page contentTypetext/html;charsetUTF-8 languagejava %
% taglib prefixc urihttp://java.sun.com/jsp/jstl/core %
html
headtitle c:choose /title
/head
bodyc:set scopepage varage value20/br---------------使用java语言------------------br%if(Integer.parseInt((String)pageContext.getAttribute(age)) 18){%输出您今年成年了% }else if(Integer.parseInt((String)pageContext.getAttribute(age)) 18){ %输出您已经成年了% }else{ %输出您还是个孩子% } %br---------------使用JSTL标签------------------brc:choosec:when test${age eq 18}输出您今年成年了/c:whenc:when test${age gt 18}输出您已经成年了/c:whenc:otherwise输出您还是个孩子/c:otherwise/c:choose
/body
/html
2.3.4.c: forEach
循环遍历
c:forEach var申明循环变量的名称 begin初始化循环变量end循环变量可以接受的最大值 step循环变量的递增或递减值*** step属性可以不写默认递增1*** 循环变量默认保存在pageContext中
/c:forEach
% page importjava.util.ArrayList %
% page importjava.util.HashMap %
% page importjava.util.List %
% page importdao.Student %
% page contentTypetext/html;charsetUTF-8 languagejava %
% taglib prefixc urihttp://java.sun.com/jsp/jstl/core %
html
headtitle c:forEach /title
/head
body%pageContext.setAttribute(students,new ArrayList(){{add(new Student(01,zhangsan,16));add(new Student(02,lisi,19));add(new Student(03,wangwu,15));}});pageContext.setAttribute(stuMap,new HashMap(){{put(s1,new Student(01,zhangsan,16));put(s2,new Student(02,zhangsan,19));put(s3,new Student(03,zhangsan,15));}});%br---------------使用java语言----------------brtabletrtd学号/tdtd姓名/tdtd年龄/td/tr%ListStudent students (ArrayListStudent)pageContext.getAttribute(students);for (int i 0; i students.size(); i) {%trtd%students.get(i).getSid()%/tdtd%students.get(i).getName()%/tdtd%students.get(i).getAge()%/td/tr% } %/tablebr---------------使用JSTL标签读取list----------------brtabletrtd学号/tdtd姓名/tdtd年龄/td/trc:forEach varstu items${students}trtd${stu.sid}/tdtd${stu.name}/tdtd${stu.age}/td/tr/c:forEach/tablebr---------------使用JSTL标签读取Map----------------brtabletrtdkey值/tdtd学号/tdtd姓名/tdtd年龄/td/trc:forEach varstu items${stuMap}trtd${stu.key}/tdtd${stu.value.sid}/tdtd${stu.value.name}/tdtd${stu.value.age}/td/tr/c:forEach/tablebr---------------使用JSTL标签读取指定for循环----------------brc:forEach varitem begin1 end10 step1option ${item} /option/c:forEach
/body
/html
其中使用的javaBean
public class Student {private String sid;private String name;private int age;
public String getSid() {return sid;}
public void setSid(String sid) {this.sid sid;}
public String getName() {return name;}
public void setName(String name) {this.name name;}
public int getAge() {return age;}
public void setAge(int age) {this.age age;}
public Student(String sid, String name, int age) {this.sid sid;this.name name;this.age age;}
}
三、Listener、Filter
3.1.概念 servlet
servlet是一种运行服务器端的java应用程序他可以用来处理请求和响应。 filter
过滤器不像servlet它不能产生一个请求或者响应它是一个中间者能修改处理经过它的请求和响应并不能直接给客户端响应。 listener
监听器它用来监听容器内的一些变化如session的创建销毁等。当变化产生时监听器就要完成一些工作。
3.2.生命周期
1、servlet: servlet的生命周期始于它被装入web服务器的内存时并在web服务器终止或重新装入servlet时结束。servlet一旦被装入web服务器一般不会从web服务器内存中删除直至web服务器关闭或重新开始。
1.装入启动服务器时加载Servlet的实例
2.初始化web服务器启动时或web服务器接收到请求时或者两者之间的某个时刻启动。初始化工作由init()方法负责执行完成
3.调用从第一次到以后的多次访问都是只调用doGet()或doPost()方法
4.销毁停止服务器时调用destory()方法销毁实例。
2、filter: 一定要实现javax.servlet包的Filter接口的三个方法init()、doFilter()、destory()空实现也行
1.启动服务器时加载过滤器的实例并调用init()方法来初始化实例
2.每一次请求时都只调用方法doFilter()进行处理
3.停止服务器时调用destory()方法销毁实例。
3、listener: 类似于servlet和filter
servlet2.4规范中提供了8个listener接口可以将其分为三类分别如下 第一类与servletContext有关的listener接口。包括ServletContextListener、ServletContextAttributeListener; 第二类与HttpSession有关的Listener接口。包括HttpSessionListener、HttpSessionAttributeListener、HttpSessionBindingListener、HttpSessionActivationListener; 第三类与ServletRequest有关的Listener接口包括ServletRequestListener、ServletRequestAttributeListener web.xml 的加载顺序是context- param - listener - filter - servlet
3.3.使用方式 listener: import javax.servlet.ServletRequestAttributeEvent;
import javax.servlet.ServletRequestAttributeListener;
import javax.servlet.ServletRequestEvent;
import javax.servlet.ServletRequestListener;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
public class TestListener implements HttpSessionListener, ServletRequestListener, ServletRequestAttributeListener {//sessionListener start!Overridepublic void sessionCreated(HttpSessionEvent httpSessionEvent) {logger.info(............TestListener sessionCreated().............);}
Overridepublic void sessionDestroyed(HttpSessionEvent httpSessionEvent) {logger.info(............TestListener sessionDestroyed().............);}//sessionListener end!
//requestListener start!Overridepublic void requestInitialized(ServletRequestEvent servletRequestEvent) {logger.info(............TestListener requestInitialized().............);}
Overridepublic void requestDestroyed(ServletRequestEvent servletRequestEvent) {logger.info(............TestListener requestDestroyed().............);}//requestListener end!
//attributeListener start!Overridepublic void attributeAdded(ServletRequestAttributeEvent servletRequestAttributeEvent) {logger.info(............TestListener attributeAdded().............);}
Overridepublic void attributeRemoved(ServletRequestAttributeEvent servletRequestAttributeEvent) {logger.info(............TestListener attributeRemoved().............);}
Overridepublic void attributeReplaced(ServletRequestAttributeEvent servletRequestAttributeEvent) {logger.info(............TestListener attributeReplaced().............);}//attributeListener end!
} Filter: import javax.servlet.*;
import java.io.IOException;
public class TestFilter implements Filter {
Overridepublic void init(FilterConfig filterConfig) throws ServletException {
}
Overridepublic void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {System.out.println(过滤器被执行了);//放行filterChain.doFilter(servletRequest,servletResponse);}
Overridepublic void destroy() {
}
} Servlet: import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
public class TestServlet extends HttpServlet {
Overridepublic void init() throws ServletException {super.init();}
Overrideprotected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {super.doGet(req, resp);}
Overrideprotected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {super.doPost(req, resp);//...TestdoPost doPost() start...//操作Attributereq.setAttribute(a,a);req.setAttribute(a,b);req.getAttribute(a);req.removeAttribute(a);
//操作sessionreq.getSession().setAttribute(a,a);req.getSession().getAttribute(a);req.getSession().invalidate();//...TestdoPost doPost() end...}
Overridepublic void destroy() {super.destroy();}
} 配置XML !-- 测试filter --
filterfilter-nameTestFilter/filter-namefilter-classtest.TestFilter/filter-class
/filter
filter-mappingfilter-nameTestFilter/filter-nameurl-pattern*.do/url-pattern
/filter-mapping
!-- 测试servlet --
servletservlet-nameTestServlet/servlet-nameservlet-classtest.TestServlet/servlet-class
/servlet
servlet-mappingservlet-nameTestServlet/servlet-nameurl-pattern/*/url-pattern
/servlet-mapping
!-- 测试listener --
listenerlistener-classtest.TestListener/listener-class
/listener
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/web/85547.shtml
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!