日常编程遇到问题的经验总结

一.JSTL:

问题:According to TLD or attribute directive in tag file, attribute value does not accept any expressions 

2.4及以后写成(JSTL1.1) :

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

2.3及以前(JSTL1.0) 

<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>

 

二. JAVA WEB编码设置与表单提交的关系:

      总结自http://student.csdn.net/space.php?uid=44933&do=blog&id=23582

TOMCAT5.X及以上处理方式区别:

1.GET方式

  GET方式将会忽略 request.setCharacterEncoding的编码设置,而采用服务器的内置编码为iso-8859-1。所以对于编码转换需要手工使用

String name = new String(request.getParameter("name").getBytes("ISO-8859-1"), "UTF-8");

2.POST方式

  POST方式将会使用request.setCharacterEncoding的编码设置,未设置则默认使用iso-8859-1

基于以上最稳妥方案为使用手工编码!

String name = new String(request.getParameter("name").getBytes("ISO-8859-1"), "UTF-8");

但这样就无法得到过滤器的便利!往往事情就是这样~不可能两全其美,需要大家自己去权衡利弊!

我的处理方式:

1. web.xml添加一个应用参数

<context-param>
	<param-name>encode</param-name>
	<param-value>UTF-8</param-value>
</context-param>

2. 自定义的servlet定义一属性并重写init()方法:

private String encode = null;

@Override
public void init() throws ServletException {
	super.init();
	if (encode == null)
		encode = super.getServletContext().getInitParameter("encode");
	System.out.println("servlet得到应用参数:" + encode);
}

3. 自定义的servlet添加一个工具方法,用于进行参数的取值和编码转换工作!

private String param(HttpServletRequest req, String name) {
	Object obj = (Object) req.getParameter(name);
	String value = obj != null ? (String) obj : "";
	try {
		value = new String(value.getBytes("iso-8859-1"), encode);
	} catch (UnsupportedEncodingException e) {
		e.printStackTrace();
	}
	return value;
}

4.实际取得某个名称的参数值,如此调用:

String username = param(req, "username");

这样就解决了参数编码转换问题,当然对于多值参数,也可以参照写一个工具方法!

三、mysql在不同系统间的大小写敏感性问题

参考:http://www.chinaz.com/Program/Mysql/060411N322010.html

1. 操作系统的敏感性决定数据库和表命名的大小写敏感。

2. 这就意味着数据库和表名在 Windows 中是大小写不敏感的,而在大多数类型的 Unix 系统中是大小写敏感的。

3. 避免这个问题的另一个办法就是以 -O lower_case_table_names=1 参数启动 mysqld。缺省地在 Windows 中这个选项为 1 ,在 Unix 中为 0

4. 如果 lower_case_table_names 为 1 ,MySQL 将在存储与查找时将所有的表名转换为小写。

eclipse 中自己设置的tomcat无法正常使用,启动正常,外部浏览器无法访问

参考:http://zhidao.baidu.com/question/143479928.html

解决方法:双击servers窗口中配置的tomcat,出现配置面板在编辑器中,在“Server locations”选择第二个Use Tomcat installation....-〉保存即可,重启tomcat,但能正常启动和运行啦~~~

原文地址:http://my.oschina.net/qt16265/blog/13905


你可能感兴趣的:(日常编程遇到问题的经验总结)