北京网站建设+招聘信息注册企业注册公司

当前位置: 首页 > news >正文

北京网站建设+招聘信息,注册企业注册公司,申请网站官网,蘑菇头表情包制作网站一、C标签 一】 c:out value… default… escapeXmltrue escapeXml:将value中的特殊符号进行转义。如果不指定为false#xff0c;那么默认值为true。 value:输出到浏览器中的值 defau… 一、C标签     一】 c:out value… default… escapeXmltrue             escapeXml:将value中的特殊符号进行转义。如果不指定为false那么默认值为true。             value:输出到浏览器中的值             default:value值找不到时的默认值         code:      c:out valuehello word! /%pageContext.setAttribute(username, jack);%br /用户名:c:out value\({username} / br /用户名:c:out value\){fdusername} default未知/ br /链接c:out valuea href#下载/a escapeXmlfalse / br /链接c:out valuea href#下载/a escapeXmltrue / br /链接c:out valuea href#下载/a / br/                 二】c:set var/value/scope/target/property          var: 有两成含义。变量名 和 存入域对象的名称。          target和property是针对于javaBean的。          code: c:set varname value杰克 scopepage/c:out value\({name} / br /jsp:useBean iduser classcom.suse.domain.User scopepage /c:set target\){user} propertyuserName valuejack /c:out value\({user.userName} / br /%MapString, Integer map new HashMapString, Integer();pageContext.setAttribute(map, map);%c:set target\){map} propertykey valuejack/c:set target\({map} propertyvalue value7000/c:out value\){map.key} / br /c:out value\({map.value} /       三】c:remove /         c:remove varvarName [scope{page|request|session|application}]         code: c:set varname valuejack scopepage /c:out value\){name} default未知 /c:remove varname scopepage/c:out value\({name} default未知 /     四】c:catch var..             ...可能出错的代码         /c:cath         var:会将错误信息封装在此         code: c:catch varmessage%int a 10/0;%/c:catchc:out value\){message} default无异常 /     五】c:if var/test/scope             var:保存test属性的结果。true or false             test:布尔值决定是否处理标签体中的内容             scope:将test属性的结果保存到哪个域对象中。         code: c:if test\({2516} varflag scoperequest2516/c:ifjsp:forward pagevalue.jsp /     六】c:choose             c:when test...                     。。。             /c:when             c:otherwise                     。。。             /c:otherwise         /c:choose         **\){param.age}  得到地址栏参数age的值         code: c:choosec:when test\({param.age 16}你成年了/c:whenc:otherwise你还未成年/c:otherwise/c:choose       七】c:forEach var/items/varStatus/begin/end/step .. /c:forEach         var:将当前迭代到的元素保存到page这个域对象中的属性名称         items:要进行迭代的的集合对象         varStatus:是个page域对象。保存着此时迭代的信息。                      属性first:是否为第一个(true or false)  index当前下标                           count:计数          end:是否为最后一个(true or false)         code:          %ListString list new ArrayListString();list.add(jack);list.add(merry);list.add(berry);list.add(xixi);list.add(sisi);request.setAttribute(list, list);%c:forEach varitem items\){list} varStatusstatus\({status.index} - \){item} - \({status.first} - \){status.last} - \({status.count} br //c:forEach     八】 c:url var/value/scope     九】 c:param name/value     十】c:redirect url 重定向             eg: c:redirect url/value.jspc:param namecountry value美国c:param nametel value123/c:redirect     十一】中文通过GET方式传参的乱码解决问题 传统方式a href/day17/c/value.jsp?country%URLEncoder.encode(中国, UTF-8)%age21传统方式传中文/aJSTL标签方式(c:url、c:redirect需要配合c:param联合使用)c:url varmyUrl value/c/value.jsp scopepagec:param namecountry value中国 /c:param nameage value15 //c:urla href\){myUrl} JSTL标签传递中文方式 /a 二、EL表达式     一】获取数据:(获取的对象必须是域对象中存储了的对象)         普通变量         JavaBean对象             略         Collection(Set和List)对象         code:            c:set varname valuejack scopepage/姓名\({name} br /%ListString list new ArrayListString();list.add(jack);list.add(merry);list.add(berry);pageContext.setAttribute(list, list);%用户列表 br /\){list[0]},,,,, \({list[1]} ,,,,,, \){list[2]}Map对象code:%MapString, String map new LinkedHashMapString, String();map.put(name, xixi);pageContext.setAttribute(map, map);%br /\({map.key} —— \){map.value} or\({map[name]}---\){map[age]}eg:c:forEach varentry items\({map}\){entry.key} : \({entry:value}/c:forEach数组对象eg:%int[] intArray {10, 20, 30};pageContext.setAttribute(intArray, intArray);%第一个元素\){intArray[0]}第二个元素\({intArray[1]}         注意             1、必须要放到域对象中。             2、若找不到返回空白字符串,而不是null         总结             \){user.address.city}             \({user.like[0]} 获取有序集合某个位置的元素             \){user.[key]} : 获得map集合中指定key的值     二】执行运算         1关系运算符             等于     或 eq   eg: \({5 5} 、 \){5 eq 5}                不等于 ! 或 ne   eg: \({4 ! 5} 、 \){4 ne 5}             小于   或者 lt             大于     或者 gt             小于等于: 或者 le             大于等于: 或者 ge         2逻辑运算符             交集 and   eg: { A B } \({A and B}             并集|| or    eg: { A || B}  \){A or B}             非  !  not    eg: {!A}       \({not A}         3**重点使用             empty:检查变量是否为null或者;             二元表达式\){user!null ? user.name : }             eg:(用户类型用户或者游客显示)             c:set varusername valuejack scopesession/             欢迎\({!empty username?username:游客 }光临     三】获取web开发常用对象(隐式方法)         1jsp九大内置对象             page/pageContext - request - session - application             response/out             config/exception         2web开发常用EL对象(总共11个)             1pageContext                 eg:                     得到对应的web应用名称                         \){pageContext.request.contextPath}             2pageScope、requestScope、sessionScope、applicationScope                 eg                     c:set varusername valuejack scopepage/                     c:set varusername valuemerry scoperequest                     用户名                         \({pageScope.username} br/  jack                         \){pageScope.username} br/  merry             3param和paramValues取得地址栏的请求参数                 param:取得单个参数                     eg:                         a href\({pageContext.request.contextPath}/param.jsp?usernamejackpassword123                         ----------                         用户名\){param.username}    jack                         密码\({param.password}         123                 paramValues:取得所有的参数                     eg:                         a href\){pageContext.request.contextPath}/param.jsp?likesinglikedancinglikeeat                         —                         爱好\({paramValues[0]}、\){paramValues[1]}、\({paramValues[2]}             4)header和headerValues取得请求头字段                 eg:                     浏览器相关信息:\){header[User-Agent]}br/   Mozlila/4.0…                     字符编码相关信息:\({headerValues[Accept-Encoding][0]}  gzip.deflate             5)cookie取得Cookie的值                 eg:                     %                         Cookie cookie  new Cookie(username, jack);                         cookie.setMaxAge(5*60);                         response.addCookie(cookie)                     %                 Cookie的名\){cookie.username.name} br/  username                 Cookie的值\({cookie.username.value} br/ jack             6)initParam获取web初始化参数                 WebName \){initParam.webName} br/                 WebAuthor \({initParam.webAuthor} br/         补充             1web初始化参数配置web.xml获得             context-param                 param-namewebName/param-name                 param-valueday17/param-value             /context-param             context-param                 param-namewebAuthor/param-name                 param-valuejack/param-value             /context-param             context-param                 param-name/param-name                 param-value/param-value             /context-param                 2jsp有9个内置对象     四】EL自定义函数         过程             1)写一个EL函数处理类该类无需继承和实现任何类或接口             2)在WEB-INF下创建一个tld文件,描述自定义函数和对应处理类的关系(函数声明一定要使用全类型)             3)在需要使用的jsp文件中通过%taglib%指令引入对应的EL函数         eg:将特殊字符进行转换EL自定义函数的实现 code:public class Filter {public static String filter(String message) {...转换代码....}}tld:tlib-version1.0/tlib-versionshort-nameskyel/short-nameurihttp://www.suse.com/jsp/jstl/el/urifunctionnamefilter/namefunction-classcom.suse.el.Filter/function-classfunction-signaturejava.lang.String filter(java.lang.String)/function-signature //函数的签名参数和返回值一定要用全类型/functionjsp(使用过滤标签)\){el:filter(scriptwhile(true){alert(haha);}/script)}eg2:验证函数\({el:checkPwd(123456, 123456)}1,检查密码是否都填写了2,检查密码是否为6位数字(正则表达式)3,检查两次密码是否一致code:public class CheckFunction {//注意此方法必须为static,否则会抛出空指针异常public static Boolean check(String password, String repassword) {if (password null || password.trim().length() 0) return false;if (password null || repassword.trim().length() 0) return false;if (!password.equals(repassword)) return false;return true;}}tld:jsp(使用):     五】EL自定义函数和自定义标签有何不同适合于什么样的场景         EL自定义函数             适合于与非web相关的应用,例如字符串相关的处理             相关函数开发过程参见《EL自定义函数开发步骤.txt》         自定义标签:             适用于与web相关的应用因为标签中有pageContext对象     六】EL内置函数(导入标签库functions)         1)字符串转小写fn:toLowerCase(ABC) 、fn:toUpperCase(abc)             eg                 转大写:\){fn:toUpperCase(abc)}                 转小写:\({fn:toLowerCase(ABC)}         2)删除字符串首位空格: trim                 eg:                     \){fn:trim( abc )}         3求字符串长度: length                 eg:                     \({fn:length( abc )}  5                     \){fn:length(fn.trim( abc ))}  3         4)*分隔字符串,生成字符串数组: split                 eg:                     \({cn:split(www.suse.com, .)[0]} br/ www                     \){cn:split(www.suse.com, .)[1]} br/ suse         5)*合并字符串数组为字符串                 eg:                     %                         String[] sArr {www, suse, cn};                         pageContext.setAttribute(SARR, sArr);                     %                     合并字符串\({fn:join(SARR, .)} www.suse.cn         6)子串在字符串的位置fn:indexOf                 eg:                     \){fn.indexOf(www.suse.com, suse)}  4                     \({fn.indexOf(www.suse.com, sfds)}  -1(找不到。返回-1)         7)是否包含子串 fn:contains 和 fn:containsIgnoreCase                 eg:                     \){fn:contains(www.suse.com, suse)} true                     \({fn:contains(www.suse.com, suSe)} false                     \){fn:containsIgnoreCase(www.suse.com, suSe)} true         8)fn:startsWith 和 fn:endsWith  判断字符串是否按指定子串开始或者结束                 eg:                     \({fn:startsWith(http://localhost:8080/.../a.jsp, http)}  true                                             \){fn:endsWith(http://localhost:8080/…/a.jsp, jsp)}     true         9)替换字符串 fn:replaces                 eg:                     \({fn:replaces(www suse com, , .)}  www.suse.com         10)*截取子串:fn:substring 和 cn:subStringBefore  、 subStringAfter                 eg:                     \){fn:substring(www.suse.com, 4, 8)} suse                     \({fn:substringAfter(www.suse.com, .)} suse.com                     \){fn:subStringBefore(www.suse.com, .)} www.suse 三、国际化     一】概念         1不同的国家访问同一个jsp页面显示的内容和样式是不同的,这样的jsp页面技术就叫做国际化。         2不能在jsp页面中写固定的内容     二】国际化的特征         1》固定数据             方法一利用javase类ResourceBundle                 ResourcesBundle:创建时指定资源包的基名和对应的Locale(语言和国家的集合:【通过浏览器的工具–Internet选项–语言–添加】查看某个国家具体的集合信息。)                 步骤                     1写一个本地化的jsp页面                     2再将本地化的jsp页面中的内容提出到资源包中即:.properties文件                     3通过ResourceBundle加载资源包                 注意在找不到匹配的资源包时会首先寻找操作系统语言标准的资源文件若还没有找到才会找默认的资源文件。                 eg1:                     1)properties:                     //en_US和zn_CN是按照标准写的                     美国资源文件    message_en_US.properties                                     helloHello                     中国资源文件    message_zh_CN.properties                                     hello\u4F60\u597D                     默认资源文件    message.properties                                     helloxxxxx                         注当没有对应国家的配置文件时,先找操作系统所对应的语言的配置文件再走默认的配置文件。                     2)code:                         //使用JavaAPI操作国际化资源                         //a)绑定对应的资源文件                         ResourceBundle rb ResourceBundle.getBundle(com/suse/message, Locale.CHINA);                         //b从资源文件中获取对应的信息                         String value rb.getString(Hello);                         //c)显示国际化信息                         System.out.println(value value);//中国                         注意Locale.US hello                               Locale.getDeafult() 你好                         code:                  ResourceBundle rb ResourceBundle.getBundle(com/suse/config/message, Locale.CHINA);String value rb.getString(hello);System.out.println(value);//hellorb ResourceBundle.getBundle(com/suse/config/message, Locale.US);value rb.getString(hello);System.out.println(value);//你好rb ResourceBundle.getBundle(com/suse/config/message, Locale.getDefault());System.out.println(value);//你好                 方法二web方案(通过ServletRequest可以获取到请求用户的Locale)                     总结 开发步骤                         1写一个本地化的jsp页面                         2将本地化的jsp页面中的内容踢出到资源包中即属性文件.oproperties                         3通过ResourceBundle加载资源包                     eg2: //properties//message_en_US.propertieslogin.titleLOGIN INlogin.usernameUSERNAMElogin.passwordPASSWORDlogin.submitSUBMIT//message_zh_CN.propertieslogin.titleLOGIN INlogin.usernameUSERNAMElogin.passwordPASSWORDlogin.submitSUBMIT//jsp%ResourceBundle bundle ResourceBundle.getBundle(com/suse/config/message,request.getLocale());%form action methodposttable border2 aligncentercaption% bundle.getString(login.title)%/captiontrth% bundle.getString(login.username)%/thtdinput typetext nameusername//td/trtrth% bundle.getString(login.password) %/thtdinput typepassword namepassword//td/trtrtd colspan2 aligncenterinput typesubmit value% bundle.getString(login.submit)%//td/tr/table                 *方法三:国际化标签                 需导入包:fmt                 注意在web中。若请求找不到对应的Locale,即访问默认的.properties文件资源包。                //properties//message_en_US.propertieslogin.titleLOGIN INlogin.usernameUSERNAMElogin.passwordPASSWORDlogin.submitSUBMIT//message_zh_CN.propertieslogin.titleLOGIN INlogin.usernameUSERNAMElogin.passwordPASSWORDlogin.submitSUBMIT//jsp%ResourceBundle bundle ResourceBundle.getBundle(com/suse/config/message,request.getLocale());%form action methodposttable border2 aligncentercaption% bundle.getString(login.title)%/captiontrth% bundle.getString(login.username)%/thtdinput typetext nameusername//td/trtrth% bundle.getString(login.password) %/thtdinput typepassword namepassword//td/trtrtd colspan2 aligncenterinput typesubmit value% bundle.getString(login.submit)%//td/tr/table             code:                 通过下拉框由用户自己选择语言的实现原理                     script typetext/javascriptfunction refresh() {var myForm document.getElementById(form);myForm.submit();}/scriptbodyfmt:setLocale value\({param.language} /fmt:setBundle basenamecom/suse/config/message /当前语言为\){param.language}br /fmt:message keylanguage.title /form idform action/day17/practice/language.jsp methodPOSTselect namelanguage οnchangerefresh()option valuezh_CN\({(zh_CNparam.language) ? selected : }fmt:message keylanguage.chinese //optionoption valueen_US\){(en_USparam.language) ? selected : }fmt:message keylanguage.english //option/select/form/body                          2》动态数据的国际化                 一)format方法: 日期 字符串                 1)格式化日期时间————Calendar类(查文档)                     Canlendar c Canlendar.getInstance(Local.CHINA);                     c.setTime(date);//设置Date对象                     c.get(Canlendar.YEAR);//得到年份                     c.get(Canlendar.MONTH);//得到月份                     c.get(Canlendar.DAY_OF_MONTH);//得到一个月的第几天                     c.get(Canlendar.DAY_OF_YEAR);//得到一年的第几天                     c.get(Canlendar.DAY_OF_WEEK);//得到一周中的第几天                     …                 2)格式化日期时间————DateFormat类和SimpleDateFormat类(查文档)                     日期DataFormat dateFormat DateFormat.getInstance(DateFormat.FULL, Locale.CHINA);                           String time dateForamt.format(new Date());                         中国:                       美式:                             SHORT:年-月-日                 SHORT:日/月/年                                   DEFAULT:2014-12-11               DEFAULT:Dec 11, 2014                             MEDIUM:2014-12-11               MEDIUM:Dec 11, 2014                             FULL:2014年12月11日 星期四       FULL:Thursday, December 11, 2014                         eg:               DateFormat dateFormat DateFormat.getDateInstance(DateFormat.SHORT, Locale.CHINA);String time dateFormat.format(new Date());System.out.println(time);dateFormat DateFormat.getDateInstance(DateFormat.SHORT, Locale.US);time dateFormat.format(new Date());System.out.println(time);///String time 2014-12-11 下午09时58分07秒 CST;DateFormat dateFormat DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.FULL , Locale.CHINA);Date date dateFormat.parse(time);Calendar c Calendar.getInstance(Locale.CHINA);c.setTime(date);System.out.println(c.get(Calendar.YEAR));System.out.println(c.get(Calendar.MONTH));System.out.println(c.get(Calendar.DAY_OF_MONTH));                         时间DateFormat dateFormat DateFormat.getTimeInstance(DateForamt.FULL, Locale.CHINA)                              String time dateFormat.format(new Date());                              结果省略.                              DateFormat dateFormat DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.FULL , Locale.CHINA);                           String date dateFormat.format(new Date());                           System.out.println(date); //2014-12-11 下午09时58分07秒 CST                        使用SimpleDateFormat类此类是DateFormat类的子类:                            eg:                                SimpleDateFormat sdf new SimpleDateFormat(yy-MM-dd, Locale.CHINA);                                Date date sdf.parse(2014-12-11);                                ///                                SimpleDateFormat sdf new SimpleDateFormat(yy-MM-dd);                                String str sdf.format(new Date());                                System.out.println(str);                        总结                            1)DateFormat不适合对日期进行判断                            2)DateFormat在多线程访问下不安全,需要使用ThreadLocaleDateFormat类确保线程安全.                 二)parse方法: 字符串 日期                     (略)             标签fmt:format 和 fmt:timeZone             %//创建时区(默认08:00时区即北京时区)TimeZone tz TimeZone.getDefault();pageContext.setAttribute(tz, tz);%jsp:useBean idnow classjava.util.Date scopepage /中国:fmt:timeZone value\({tz}fmt:formatDate value\){now} typeboth dateStylefull timeStylefull//fmt:timeZonehr /美国fmt:timeZone valueGMT-08:00fmt:formatDate value\({now} typeboth dateStylefull timeStylefull//fmt:timeZonehr /开罗:fmt:timeZone valueGMT02:00fmt:formatDate value\){now} typeboth dateStylefull timeStylefull//fmt:timeZonehr /fmt:formatDate value\({now} patternyyyy-MM-dd-w-F-E hh:mm:ss timeZoneGMT-08:00/               3)时区:timeZone                  (略)             4)格式化数字————NumberFormat类                     format方法将一个数值格式化为符合某个国家地区习惯的数值字符串                     parse方法将符合某个国家地区习惯的数值字符串解析为对应的数值                     getIntegerInstance(Locale local)方法: 以本地的规范处理整数字符串信息为数字。                     getCurrencyInstance(Locale locale)方法: 以本地的规范处理货币信息为数字。                     getPercentInstance(Locale locale)方法: 以本地的规范处理百分比信息为数字。                 code:                   NumberFormat numberFormat NumberFormat.getIntegerInstance(Locale.CHINA);Long number numberFormat.parse(123).longValue();System.out.println(num number);String str numberFormat.format(123);System.out.println(str);numberFormat NumberFormat.getCurrencyInstance(Locale.CHINA);str numberFormat.format(123);System.out.println(str);//123.00number numberFormat.parse(123.00).longValue();System.out.println(number);//123numberFormat NumberFormat.getPercentInstance(Locale.CHINA);Double i numberFormat.parse(50.6%).doubleValue();System.out.println(i);//0.506str numberFormat.format(0.506);System.out.println(str);//51%                      **标签 数字fmt:formatNumber value12.56 typenumber/hr/货币fmt:formatNumber value1000 typecurrency/hr/百分比fmt:formatNumber value0.25 typepercent/hr/               5)格式化文本————MessageFormat类                 总结                     占位符的三种书写方式:                         {argumentIndex}:0-9之间,表示要格式化对象数据在参数数组中的索引。                         {argumentIndex, FormatType}: FormatType表示参数格式化类型                         {argumentIndex, FormatType, FormatStyle}: FormatStyle格式化的5种样式必须与格式化类型FormatType匹配                 code:                  //模式字符串即还有{n}占位符的字符串String pattern On {0}, a hurricance destroyed {1} houses and caused {2} of damage;MessageFormat messageFormat new MessageFormat(pattern, Locale.US);String message messageFormat.format(new Object[]{new Date(), 99, \)100000});System.out.println(message);//On 12/12/14 11:00 PM, a hurricance destroyed 99 houses and caused $100000 of damage//其他样式的占位符pattern At {0, time, short} on {0, date}, {1} destroyed \n;messageFormat new MessageFormat(pattern, Locale.US);message messageFormat.format(new Object[]{new Date(), 99});System.out.println(message);//At 11:08 PM on Dec 12, 2014, 99 destroyed       补充     将中文转换成编码         1可以通过eclipse的properties工具自动将中文转换成编码         2通过jdk的bin目录下的native2ascii工具:             //将a.txt以gb2312的方式进行编码并传入message_zh_CN中             进入cmd中                  d:\native2ascii -encoding gb2312 a.txt message_zh_CN