java web笔记(字符编码)

 

一,URL-pattern的三种模式:
1,准确路径模式:<url-pattern>/x/y/a/b</url-pattern>
访问:http://localhost/web1/x/y/a/b

2,模糊匹配模式:<url-pattern>/x/y/*</url-pattern>
访问:http://localhost/web1/x/y/a/b/dasf
http://localhost/web1/x/y/a
http://localhost/web1/x/y/

3,扩展名匹配:<url-pattern>*.do</url-pattern>
http://localhost/web1/a/sd/sadfasdfasdfdf.do
http://localhost/web1/dfdf.do
http://localhost/web1/a/sd/sadf/asdfasdfdf.do

注意:1)前两个以  /  起始
      2)*.do不能跟准确路径混用   <url-pattern>/x/y/*.do</url-pattern>


二,重点,EL表达式
EL-- expression language 表达式语言
EL是jsp2.0 支持的快捷输出 4 大属性范围值的方式。

1,4种属性
jsp页面                servlet
pageContext       
request                request形参
session                request.getSession();
application            request.getSession().getServletContext()

2,优点:
1)null值不显示
2)控制对象属性  p1.birth.year----->p1.getBirth().getYear()

3,同名值的问题:
EL会按照 pageContext ,request ,session ,application的顺序去查找,一旦找到,停止搜索。
如何解决:
request-->${requestScope.s1 }<br>
   session-->${sessionScope.s1 }<br>
   application-->${applicationScope.s1 }<br>

一、tomcat server.xml

1行 <?xml version='1.0' encoding='utf-8'?>
67行 <Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" URIEncoding="utf-8"/>
最后 <Context path="/tang8" docBase="E:\tangchuang\MyEclipse File\案例8\WebRoot"  />

二、MyEclipse window--Preferences
①、General--Editors--Text Editors--Spelling
②、General--Workspace--Other
③、MyEclipse--Files and Editors--JSP--Encoding

三、MySQL
C:\Program Files\MySQL\MySQL Server 5.0
57行、81行 改gbk
改完以后要重启服务、重启cmd、重新运行脚本。

四、提交
①、POST方式
 <%   request.setCharacterEncoding("utf-8");   %>
②、GET方式
 <%   request.setCharacterEncoding("utf-8");   %>
 tomcat还要加67行的最后一句,URIEncoding="utf-8"
③、自动跳转的编码问题
<%
     String a="mike李tom";
     int b=123;   
     %>
    
     <%
        String aa = URLEncoder.encode(a,"utf-8"); 
      //response.sendRedirect("test2.jsp?t1="+aa+"&t2="+b);
      %>
 
到了:test2.jsp
<%

 String aa = request.getParameter("t1");
 String aaa = URLDecoder.decode(aa,"utf-8");
%>

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值