使用IDEA开发基于Appfuse(2.0.2版本,Web框架选Struts2)的...

2010/08/04, leeoo

    系统环境:Windows XP SP3 简体中文(故系统的缺省编码是GBK)+ Tomcat v6.0.29 + Idea v9.0.3 + Maven 2.2.1 + AppFuse 2.0.2

1)、生成demo运行中文乱码问题的解决
------------------------------------
    AppFuse 2.0.2生成的appfuse-basic-struts类型的demo,放在tomcat上运行,
所有的页面上的中文都变成了乱码,经过仔细测试,发现原来是项目下的pom.xml
在作怪,只需做如下三步操作就可以解决中文乱码问题了!

第一步:将pom.xml中native2ascii-maven-plugin下的
   
        native2ascii-8859_1
       
            native2ascii
       
       
            8859_1
           
                ApplicationResources_de.properties,
                ApplicationResources_fr.properties,
                ApplicationResources_nl.properties,
                ApplicationResources_pt*.properties
           
       
   
注释掉。

第二步:再在以下部分加入注释下面的内容!
   
        native2ascii-utf8
       
            native2ascii
       
       
            UTF8
           
                ApplicationResources_ko.properties,
                ApplicationResources_no.properties,
                ApplicationResources_tr.properties,
                ApplicationResources_zh*.properties,
               
                displaytag_zh*.properties,
                errors_zh*.properties

第三步:在以下部分(在段的第一个段)作如下修改!
   
        src/main/resources
       
            ApplicationResources_de.properties
            ApplicationResources_fr.properties
            ApplicationResources_ko.properties
            ApplicationResources_nl.properties
            ApplicationResources_no.properties
            ApplicationResources_pt*.properties
            ApplicationResources_tr.properties
            ApplicationResources_zh*.properties
            applicationContext-resources.xml
            struts.xml
           
            displaytag_zh*.properties
            errors_zh*.properties
       
        true

第四步:最后在IDEA的Settings中修改一下IDEA编译(其实就是IDEA的Make操作)时将中文相关的语言资源文件忽略!具体作法如下:
单击File -> Settings -> Compiler -> Excludes,通过[Add]按钮添加src\main\resources下需要忽略的中文语言资源文件,比如

ApplicationResources_zh.properties,
ApplicationResources_zh_CN.properties,
ApplicationResources_zh_TW.properties, displaytag_zh.properties,
displaytag_zh_CN.properties,
displaytag_zh_TW.properties, errors_zh.properties,
errors_zh_CN.properties,
errors_zh_TW.properties

一般情况下,我的项目只需关注简体中文和英文两种语言环境,所以没必要将上面的文件都忽略,只需忽略如下几个简体中文语言资源文件即可!
ApplicationResources_zh_CN.properties,
displaytag_zh_CN.properties,
errors_zh_CN.properties,

至此,中文乱码问题解决!!!
PS:不知道在非GBK编码操作系统环境下这样修改能否有效,有待测试!!!


2)、启动tomcat“一闪而过”问题的解决
---------------------------------------
原因:可能是没有生成编译后的项目Web运行目录。

解决办法:对于(1),只需写上这个配置文件即可!
对于(2),只需在运行Idea的Maven Projects视图中的Lifecycle中的install命令(为了
生成编译后的项目Web运行目录)即可!

 


3)、启动tomcat后,在浏览器中打开项目首页地址报404错误问题的解决
------------------------------------------------------------------
原因:可能是配合Idea远程调试的配置文件(在tomcat的conf\Catalina\localhost
目录下)不存在。

解决办法:只需写上这个项目对应的远程调试的配置文件放到在tomcat的
conf\Catalina\localhost目录下,再重新启动tomcat即可!


4)、修改中文语言等资源文件后“不生效”问题的解决
------------------------------------------------
原因:只是运行了Idea的make,没有运行maven生命周期中的compile命令。

解决办法:运行maven生命周期中的compile命令,再运行Idea的make即可!

5)、
------------------------------------------------

异常:

在maven中执行dbunit:operation时报如下错误:

[INFO] ------------------------------------------------------------------------

[INFO] [dbunit:operation]

[INFO] ------------------------------------------------------------------------

[ERROR] BUILD ERROR

[INFO] ------------------------------------------------------------------------

[INFO] Error executing database operation: CLEAN_INSERT

 

Embedded error: com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException: Cannot add or update a child row: a foreign key constraint fails (`sdcm/color_coordinate`, CONSTRAINT `FK9FC22FD4FA5FE471` FOREIGN KEY (`rated_color_id`) REFERENCES `rated_color` (`rated_color_id`))

 

原因:

 

解决办法:

到ColorCoordinate.java类中,做如下调整,

    // TODO 这里的@OneToOne中一定不要加optional = false,否则在生成测试数据时报 “Error executing database operation: CLEAN_INSERT Embedded error: java.sql.SQLException: Field 'rated_color_id' doesn't have a default value”错误

    @OneToOne(cascade = CascadeType.ALL)

    @JoinColumn(name = "rated_color_id")

    public RatedColor getRatedColor() {

        return ratedColor;

    }

==============================================================================

    // TODO 以下两个以单个字母开头为一个单词的,按照JavaBean规范命名,要小写该属性字段的首单词的首字母的,但放在HQL中在Hibernate执行时会报语法错误,而且跟踪调试发现Hibernate根本没有到这两个属性的访问器中!

    private Double xCoordinateValue; // X坐标值

    private Double yCoordinateValue; // Y坐标值

    改为下面的就没问题了,

    private Double coordX; // X坐标值

    private Double coordY; // Y坐标值

==============================================================================

6)、

异常:

[INFO] [dbunit:operation]

[INFO] ------------------------------------------------------------------------

[ERROR] BUILD ERROR

[INFO] ------------------------------------------------------------------------

[INFO] Error executing database operation: CLEAN_INSERT

 

Embedded error: com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException: Cannot delete or update a parent row: a foreign key constraint fails (`sdcm/color_coordinate`, CONSTRAINT `FK9FC22FD4FA5FE471` FOREIGN KEY (`rated_color_id`) REFERENCES `rated_color` (`rated_color_id`))

 

原因:

是因为appfuse生成的sample-data.xml中相应表的测试数据的顺序没有遵守“无外键的表先生成,有外键字段的表后生成”的原则!!!

 

解决办法:

将各表对应的测试数据的顺序调整正确即可!!!

===============================================

7)、

异常:

[INFO] Scanning for projects...

[WARNING] 

[WARNING] Some problems were encountered while building the effective model for com.byd:demo:war:1.0

[WARNING] 'reporting.plugins.plugin.version' is missing for org.apache.maven.plugins:maven-changes-plugin @ com.byd:demo:1.0, E:\workshop\eclipse_jee\demo\pom.xml

[WARNING] 'reporting.plugins.plugin.version' is missing for org.apache.maven.plugins:maven-checkstyle-plugin @ com.byd:demo:1.0, E:\workshop\eclipse_jee\demo\pom.xml

[WARNING] 'reporting.plugins.plugin.version' is missing for org.apache.maven.plugins:maven-javadoc-plugin @ com.byd:demo:1.0, E:\workshop\eclipse_jee\demo\pom.xml

[WARNING] 'reporting.plugins.plugin.version' is missing for org.apache.maven.plugins:maven-jxr-plugin @ com.byd:demo:1.0, E:\workshop\eclipse_jee\demo\pom.xml

[WARNING] 'reporting.plugins.plugin.version' is missing for org.apache.maven.plugins:maven-pmd-plugin @ com.byd:demo:1.0, E:\workshop\eclipse_jee\demo\pom.xml

[WARNING] 'reporting.plugins.plugin.version' is missing for org.apache.maven.plugins:maven-surefire-report-plugin @ com.byd:demo:1.0, E:\workshop\eclipse_jee\demo\pom.xml

[WARNING] 

[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.

[WARNING] 

[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.

[WARNING] 

[INFO]                                                                         

[INFO] ------------------------------------------------------------------------

[INFO] Building Unnamed - com.byd:demo:war:1.0 1.0

[INFO] ------------------------------------------------------------------------

[INFO] ------------------------------------------------------------------------

[INFO] BUILD FAILURE

[ERROR] Failed to execute goal on project demo: Missing:

----------

1) com.sun:tools:jar:1.5.0

 

  Try downloading the file manually from the project website.

  Then, install it using the command: 

      mvn install:install-file -DgroupId=com.sun -DartifactId=tools -Dversion=1.5.0 -Dpackaging=jar -Dfile=/path/to/file

  Alternatively, if you host your own repository you can deploy the file there: 

      mvn deploy:deploy-file -DgroupId=com.sun -DartifactId=tools -Dversion=1.5.0 -Dpackaging=jar -Dfile=/path/to/file -Durl=[url] -DrepositoryId=[id]

  Path to dependency: 

  1) com.byd:demo:pom:pom:1.0

  2) org.apache.struts:struts2-core:jar:2.2.1

  3) com.sun:tools:jar:1.5.0

----------

1 required artifact is missing.

for artifact: 

  com.byd:demo:pom:1.0

from the specified remote repositories:

  central (http://repo1.maven.org/maven2, releases=true, snapshots=true),

  appfuse (http://static.appfuse.org/repository, releases=true, snapshots=true)

-> [Help 1]

[ERROR] 

[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.

[ERROR] Re-run Maven using the -X switch to enable full debug logging.

[ERROR] 

[ERROR] For more information about the errors and possible solutions, please read the following articles:

[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MultipleArtifactsNotFoundException

 

原因:

出现以上原因是因为jdk没有配好。我们只需要修改一下pom.xml就ok了!

 

解决办法:

 

          com.sun  

          tools  

          1.6.0  

          system  

          C:/Program Files/Java/jdk1.6.0_05/lib/tools.jar  

 

 

注意${java.home}/../lib/tools.jar我们通常是使用系统的环境变量取得java.home的路径的。

8)、JSP页面异常
===============================================================================

异常一:
当点击页面上的一个链接(这个链接是action的形式,需要被Struts2拦截处理的)

后,页面是跳转了,但是页面显示空白!!!

原因:

是链接中对应的action被Struts2处理后要转发的JSP页面中使用了Struts2的

标签,而其中的的属性写错了,一般是name属性的值写错了!!!

解决办法:
将name属性的值写正确即可!!!另外还要保证使用的由XxxAction类传递过来

的对应的JSP页面上的元素中的name属性在此XxxAction类中的get和set方法的

写法和名称要正确!!!


异常二:

当点击页面上的一个提交按钮(提交了form,需要被Struts2拦截处理的)

后,页面是跳转了,但是页面没有显示Action中查询出来的内容!!!

原因:

JSP页面用到的DisplayTag标签等需要得到这个要显示的属性数据,而得到这个属性数

据就是通过你的Action类中该属性的getter方法来获得的!!!

解决办法:
将JSP页面的DisplayTag标签中欲显示的属性的getter方法在你的Action类中正确

写上即可!!!

9)、Hibernate异常收集
-----------------------

异常:
Remember that ordinal parameters are 1-based!

原因:
问题发生的原因是:hql语句里不需要参数,却添加/缺少了一个或几个参数,删掉/添加语句中的参数即可!

解决办法:
我的HQL语句:String hql="from Users as u where u.username=‘?’ and u.userpassword=‘?’";

Object[] param=new Object[]{“admin”,“000000”};

this.getHibernateTemplate().find(hql,param);

将HQL语句中''中的?没有解析成占位符,确解析成字符串了。

改成如下形式

String hql="from Users as u where u.username=? and u.userpassword=?";

Object[] param=new Object[]{“admin”,“000000”};

this.getHibernateTemplate().find(hql,param);

问题解决!!!!

=======================================================================

异常:
The database returned no natively generated identity value; 

nested exception is org.hibernate.HibernateException: The database returned no natively generated identity value

(网上的解决办法:主键没有添加增量!把主键设置为自增长。或者添加一个自增长的字段作为主键。---但是没有解决我的问题)

原因:
虽然MySQL中已经设置了这个主键字段为auto_increment,但是这个主键字段的值刚好为0了!!!

(可在Navicat for MySQL中的设计表的Options -> Auto Increment中看到!)

解决办法:
将存储在MySQL中的这个主键的Auto Increment值从0改为其它非零正整数即可!(不知道为什么MySQL不能从0开始增长!!!)

=======================================================================

异常:
unexpected token: on near line 1, column 215 [select p.productId, p.productName, p.productDescription, rc.ratedColorTemperatureValue, cc.xCoordinateValue, cc.yCoordinateValue from com.byd.app.model.Product as p join ColorCoordinate as cc join RatedColor as rc on rc.ratedColorId = -1 and cc.productId = p.productId]; nested exception is org.hibernate.hql.ast.QuerySyntaxException: unexpected token: on near line 1, column 215 [select p.productId, p.productName, p.productDescription, rc.ratedColorTemperatureValue, cc.xCoordinateValue, cc.yCoordinateValue from com.byd.app.model.Product as p join ColorCoordinate as cc join RatedColor as rc on rc.ratedColorId = -1 and cc.productId = p.productId] 

原因:
看异常信息,可以发现是语法错误,即HQL语句中写的“on”那里报错了,这是因为Hibernate的HQL语句不支持on,在连接查询时

需要用到on的地方改为where即可!!!

解决办法:
将报错处的on改为where即可!!!

=======================================================================

异常:
query specified join fetching, but the owner of the fetched association was not present in the select list...

原因:

写道

hql.append(" from DutyCallover t left join fetch t.duty where 1=1 ");

Hibernate报错:

query specified join fetching, but the owner of the fetched association was not present in the select list

参考:

http://www.hibernate.org/250.html?cmd=prntdoc

写道

Furthermore, a query that specifies join fetching, but the owner of the fetched association was not present in the select list throws an exception now: "select b from A join fetch a.bees b" - this query makes no sense, remove the "fetch".

去掉fetch就可以,但是返回的每个Page.resultList对象是二维数组,index为0是目标对象DutyCallover,index为1是它的关联对象DutyInfo.

解决办法:
去掉其中fetch关键字即可!!!

=======================================================================

异常:

java.lang.IndexOutOfBoundsException: Remember that ordinal parameters are 1-based!

原因:

HQL语句中有不需要的参数,或者是参数的写法不正确。

如HQL语句中的占位符 ? 不需要用英文双引号或单引号括起来,你却括起来了,或者是这个占位符没有用到,你却写了!

解决办法:
将多余的占位符去掉或者把占位符改正确!

示例:

错误写法 -> String hql = "from User u where u.username='?' and u.passowrd='?'";

Object[] params = new Object[]{"admin","000000"};

this.getHibernateTemplate().find(hql, params);

正确写法 -> String hql = "from User u where u.username=? and u.passowrd=?";

Object[] params = new Object[]{"admin","000000"};

this.getHibernateTemplate().find(hql, params);

===============================================================================

10)、Maven2.x使用收集
------------------------------

问题一:maven编译时提示一堆与编码导致错误有关的问题

Maven 2.0.9版本,JDK 1.6.013版本,Idea 9.0版本,在使用maven编译时,经常会报一堆错误,

仔细查看其实没有错误,报错的地方都是有中文在附近的地方,不论中文是出现在代码中,还是

在注释中,使用maven的生命周期(Lifecycle)中的compile编译都会报错。百思不得其解,后

来发现去掉中文再编译就不会报错了,因此怀疑是maven的编译时使用的编码有问题,因此,找到

pom.xml文件,发现在Pom.xml中配置了编译插件:

 

    maven-compiler-plugin    

    2.0.2

 

        1.5

        1.5

 

 

解决办法:修改pom.xml文件,强制使用utf8的编码:

 

    maven-compiler-plugin

    2.0.2

 

        1.5

        1.5

        UTF-8

 

 

-------------------------------------------------------------------

另:http://ncowboy.blog.51cto.com/36000/334031

MVN:指定编译时的文字编码和语法级别

2010-06-17 10:45:16

方法1,

 

      package

 

 

        maven-compiler-plugin

 

         1.6

         1.6

         UTF-8

 

 

 

 

方法2,

 

        UTF-8

        1.6

        1.6

 

PS:以上方法第一种完全可用,第二种没有试过!

-------------------------------------------------------------------

问题二:  MAVEN手工添加第三方jar包(ojdbc14.jar)

第三方jar包需要手工添加,命令如下:

mvn install:install-file -Dfile=E:\maven221\repository\com\oracle\ojdbc14\10.2.0.2.0\ojdbc14-10.2.0.2.0.jar -DgroupId=com.org.common.oracle -DartifactId=oracle -Dversion=10.2.0.2.0 -Dpackaging=jar -DgeneratePom=true

11)、Tomcat异常收集
--------------------------------

异常:
tomcat启动时报以下错误(只保留了重要部分)

“Invalid   byte   3   of   3-byte   UTF-8   sequence. ”

ERROR [main] MenuContextListener.contextInitialized(69) | Failure initializing

struts-menu: Error parsing resource file: /WEB-INF/menu-config.xml nested exception

is: Invalid byte 3 of 3-byte UTF-8 sequence.

原因:
从异常报告中可以看出是menu-config.xml的编码有问题,一般是里面出现了乱码导致的!!!

解决办法:
将乱码处理掉!!!

======================================================================

异常:
2010-9-24 8:38:55 org.apache.tomcat.util.http.Parameters processParameters

警告: Parameters: Invalid chunk '=%E6%96%B0%E5%A2%9E' ignored.

原因:
在链接参数中存在一定的问题和业务逻辑没关系,

比如说在一个链接http://url?param1=value1&redundance=rValue,其中redundance没有在业务逻辑中使用。

解决办法:
方法1:在业务逻辑中使用所有传入的值;

方法2:去除冗余参数;

======================================================================

转载于:https://my.oschina.net/leeoo/blog/51048

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值