易截截图软件、单文件、免安装、纯绿色、仅160KB

5月19日 JSP基础

1.ession内的存放的是对象的引用,所以修改内置对象后,不需要重新放置到session中
2.配置Context初始化参数
<Context-param>
<param-name></paran-name>
<param-value></param-value>
<Context-param>
this.getServletContext().getInitParameter(arg0);
-----------------------------------------------------------------------------------------------------------------
3.配置servlet初始化参数
<init-param>
   <param-name></param-name>
   <param-value></param-value>
</inti-param>
ServletConfig config=this.getServletConfig();
config.getParameter(""); 
-----------------------------------------------------------------------------------------------------------------
4配置文件 properties
格式: key=value  其中key不变 value是变化的
例如: #其中"#"为注释
   文件 db.properties
    username=秦焰培
    password=peiaihua 
最好放置到/WEB-INF/db.properties  
 读取属性文件的信息:
 /在web应用中,getServletContext().getRealPath表示的
 是web工程的根路径,
 如:"C:\Program Files\apache-tomcat-6.0.18\webapps\TestURL"
 
 String path=this.getServletContext().getRealPath("");
 FileImputSream fi=new FileInputStream(path);
 Properties pro=new Properties();
 pro.load(fi);
 pro.getProperty("key");
 
 String realPath=this.getServletContext().getResourceAsStream("/WEB-INF/db.properties")
 表示的也是从根路径开始加载文件:
 -----------------------------------------------------------------------------------------------------------------
 <!--  该标签表示服务器启动时,自动创建servlet对象,而且数字越先优先级越高-->
 <Load-on-startup>0,1,2,3,....</Load-on-srartup>
 -----------------------------------------------------------------------------------------------------------------
 servlet通信(communicate):
  路径设置:
&n


相关文档:

JSP注释

今天在调试代码时,发现一段写在jsp端的java代码怎么编译,设置断点都不会在断点处停留。百思不得其解,在同事的帮助下,发现是代码注释有问题。
      原代码:
            <!-- <jsp:forward page="/hello/Welcome.do"/> - ......

JSP URL中文传参

 将参数写成 java.net.URLEncoder.encode(sContent,"gb2312")后再传递。
比如url是"/accept.do?content=<%=java.net.URLEncoder.encode(sContent,"UTF-8")%>";
读取时,使用
String sc =  new String(request.getParameter("content").getBytes("iso-8859-1"),"UTF-8"); ......

jsp的字符问题

tomcat 默认使用的字符集是ISO-8859-1,不支持中文字符,所以在现实中文时需要转换字符和设置字符集。
server.mxl改为<Connector port="8080" protocol="HTTP/1.1" maxThreads="150" connectionTimeout="20000" redirectPort="8443" URIEncoding="UTF-8" /> ,添加代码转换字符String.getBytes("ISO-8859-1"),"UTF-8 ......

jsp和Action中Base64编码转换

jsp中用javascript将中文Base64转码, Action中再用Base64解码
javascript中使用webtoolkit.base64.js,下载地址http://www.webtoolkit.info/djs/webtoolkit.base64.js
相关介绍 http://www.webtoolkit.info/javascript-base64.html
/**
*
*  Base64 encode / decode
*  http://www.webtoolkit.info/
*
**/ ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号