panpan123mail 发表于 2013-1-30 01:36:50

最近面对的一些初级技术错误问题总结

1、在运行jsp时出现报错:
错误信息:Bad version number in .class file
导致这个错误出现的根本原因是eclipse的版本同tomcat所用的JDK版本不一致,只要改下eclipse中JDK的版本就可以了。
eclipe的compiler的jdk版本设置步骤:
project --> properties --> java compiler 找到相应的位置设好就ok。

启示:当自己实在找不出问题时,请用google
2、Struts2布置若出现报错是不能找到FilterDispatcher
原因可能是由于没有加载jar:commons-fileupload-1.2.1.jar

3、出现报错异常Unable to read TLD "META-INF/c.tld"……
原因很可能是在lib加载了包jsp-api.jar,删除即可

4、出现报错异常:java.lang.LinkageError: loader constraint violation: when resolving interface method "javax.servlet.jsp.JspApplicationContext.getExpressionFactory()Ljavax/el/ExpressionFactory;"
原因可能是项目加载的jar有el-api.jar,删除即可

5、若是在jsp页面$(sessionScope.user)得不到值,再次检查是否是有错误,注意$后跟的是{}而不是()
最好换用
<s:property value="#session.user" />
但是要在页头导入struts标签<%@ taglib uri="/struts-tags" prefix="s" %>
注:#是OGNL表达式的操作符,struts2默认支持的表达式为OGNL表达式,建议不要使用EL表达式。

6、Struts2提供了三种主题,ajax, simple, xhtml,它默认的是xhtml主题中标签默认的是xhtml主题,所以一行不能显示多个标签,改正办法:在struts.xml中添加
<constant name="struts.ui.theme" value="simple" />
使其显示采取simple主题,那么在jsp中就可以使用html进行整合例了

7、在项目中遇到错误而控制台和页面不显示时,请用输出语句大多数可以看出端倪

8、遇到字符串时,若进行比较,请注意其真是长度,一般需要调用trim()方法

9、今天早上突然来了个异常:
这个 org.postgresql.jdbc4.Jdbc4ResultSet.getNString(int) 方法尚未被实作
去google搜索也没见谁出现过这样的问题,后来仔细一看,原来是在写ResultSet的getString时粗心写成getNString了。以后注意出现一些荒唐错误大多数是不细心的缘故,仔细检查并调试代码,

10、在使用PostgreSQL时,用关键字limit进行分批查询时,与别的sql语句不同,必须和OFFSET结合才可以

11、出现错误信息:ResultSet 中找不到栏位名称 001。
    很可能是你写的ResultSet的get方法有问题,或是sql语句有问题

12、在PostgreSQL中sql语句书写时特别要注意:当有大写的字母时必须用引号括起来,不然会报错如:
org.postgresql.util.PSQLException: ERROR: syntax error at or near "'shopCode'"
以上错误是因为shopCode是有个大写字母

13、弄了将近两个小时,才发现原来是PostgreSQL是由于不支持单引号的缘故,害得我一下一下地调试,在java中只好借用转义字符了,弄得我有些头大

14、在页面写页面标签时遇到异常:
According to TLD or attribute directive in tag file, attribute test does not accept any expressions
这很可能是standard标签的问题,请注意版本的不同,在页面的引入时需要注意:1.1版本以上,支持jsp2.0,把jstl.jar、standard.jar两个jar拷贝到项目下
,并在jsp页头加上
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
若是以前的版本,就需要
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
在web.xml中配置taglib如下
-----------------------------------------------------------------------------------------------
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">

<taglib>
<taglib-uri>http://java.sun.com/jstl/fmt</taglib-uri>
<taglib-location>/WEB-INF/tlds/fmt.tld</taglib-location>
</taglib>

<taglib>
<taglib-uri>http://java.sun.com/jstl/fmt-rt</taglib-uri>
<taglib-location>/WEB-INF/tlds/fmt-rt.tld</taglib-location>
</taglib>

<taglib>
<taglib-uri>http://java.sun.com/jstl/core</taglib-uri>
<taglib-location>/WEB-INF/tlds/c.tld</taglib-location>
</taglib>

<taglib>
<taglib-uri>http://java.sun.com/jstl/core-rt</taglib-uri>
<taglib-location>/WEB-INF/tlds/c-rt.tld</taglib-location>
</taglib>

<taglib>
<taglib-uri>http://java.sun.com/jstl/sql</taglib-uri>
<taglib-location>/WEB-INF/tlds/sql.tld</taglib-location>
</taglib>

<taglib>
<taglib-uri>http://java.sun.com/jstl/sql-rt</taglib-uri>
<taglib-location>/WEB-INF/tlds/sql-rt.tld</taglib-location>
</taglib>

<taglib>
<taglib-uri>http://java.sun.com/jstl/x</taglib-uri>
<taglib-location>/WEB-INF/tlds/x.tld</taglib-location>
</taglib>

<taglib>
<taglib-uri>http://java.sun.com/jstl/x-rt</taglib-uri>
<taglib-location>/WEB-INF/tlds/x-rt.tld</taglib-location>
</taglib>
</web-app>
------------------------------------------------------------------------------------------------
注:以上是在用struts2.1是遇见的问题,贴于此,以备后用
页: [1]
查看完整版本: 最近面对的一些初级技术错误问题总结