Jforum二次开发中遇到的问题与解决

来源:互联网 发布:unity3d 启动画面 编辑:程序博客网 时间:2024/04/29 06:02

Jforum二次开发中遇到的问题与解决

author:邓华锋

date: 2010-4-26

Company: JAGO Software
Copyright: Copyright (c) 2010

错误信息1:
11:53:24,781 ERROR [ExceptionWriter] net.jforum.exceptions.ForumException: java.lang.reflect.InvocationTargetException
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
……
 ... 31 more

分析原因:传给PreparedStatement的参数索引值超出范围。可能你修改了SQL语句或dao类代码,没有重新把项目加载到Tomcat服务器上,而导致运行时代码不一致,而导致抛出以上异常。
首先检查一下SQL语句:
ForumModel.removeSubscription = DELETE FROM jforum_forums_watch WHERE forum_id = :forumId:  AND user_id in (:userIds:)
而Dao代码:
String sql = SystemGlobals.getSql("ForumModel.removeSubscription");
   //sql = sql.replaceAll(":forumId:",forumId+"");
   sql = sql.replaceAll(":userIds:", this.buildInClause(userIds));
   p = JForumExecutionContext.getConnection().prepareStatement(sql);
   p.setInt(1, forumId);
   p.executeUpdate();
显然Dao类中传参方式与SQL语句参数形式不一致,导致报以上错误。
解决方法:
修改SQL语句:ForumModel.removeSubscription = DELETE FROM jforum_forums_watch WHERE forum_id = ? AND user_id in (:userIds:)
或修改Dao代码:
 String sql = SystemGlobals.getSql("ForumModel.removeSubscription");
   sql = sql.replaceAll(":forumId:",forumId+"");
   sql = sql.replaceAll(":userIds:", this.buildInClause(userIds));
   p = JForumExecutionContext.getConnection().prepareStatement(sql);   p.executeUpdate();


错误信息2:
12:05:38,562 ERROR [ExceptionWriter     ] net.jforum.exceptions.TemplateNotFoundException: Template for action subscribeUserSave is not defined
 at net.jforum.Command.process(Command.java:137)
 at ……
 at java.lang.Thread.run(Thread.java:619)

分析原因:在JForum的action的方法中,执行完方法体代码后,必须有段this.setTemplateName(TemplateKeys.**)代码来跳转页面,如果执行完方法后没有加this.setTemplateName(TemplateKeys.**)代码来跳转页面,系统则会抛出以上异常。

 

错误信息3:
00:06:25,468 ERROR [runtime             ]
Expression friend.nickname is undefined on line 36, column 65 in default/user_friend.htm.
The problematic instruction:
----------
==> ${friend.nickname} [on line 36, column 63 in default/user_friend.htm]
----------

Java backtrace for programmers:
----------
freemarker.core.InvalidReferenceException: Expression friend.nickname is undefined on line 36, column 65 in default/user_friend.htm.
 at ……org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
 at java.lang.Thread.run(Thread.java:619)
分析原因:${friend.nickname}引发了frimark的空值异常。
解决方法:在nickname文本框的值传给action当中,是否没取到nickname文本框的值,而执行了修改操作,导致最后引发了空值异常。

 

错误信息4:
11:45:42,984 ERROR [ExceptionWriter     ] net.jforum.exceptions.ForumException: java.lang.reflect.InvocationTargetException
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 at java.lang.reflect.Method.invoke(Method.java:597)
 at net.jforum.Command.process(Command.java:114)
 at net.jforum.view.admin.AdminCommand.process(AdminCommand.java:64)
 at net.jforum.JForum.processCommand(JForum.java:217)
 at net.jforum.JForum.service(JForum.java:200)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
 at ……
Caused by: java.sql.SQLException: No value specified for parameter 5
 ... 32 more
错误原因:没有指定的参数值,在dao实现类中调SQL语句时,没有指定参数值。
解决办法:检查SQL语句中是否还有些参数在dao实现类方法中没有指定参数值。

 

错误信息5
SELECT fw.category_id categoryId,fw.user_id userId,u.username,fw.moderator_order moderatorOrder,fw.newInheritedmod FROM jforum_forums_watch fw INNER JOIN jforum_users u ON u.user_id=fw.user_id WHERE fw.category_id=1 AND fw.forum_id=0order by moderatorOrder asc
 ... 47 more
Caused by: com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'by moderatorOrder asc' at line 1

Query being executed when exception was thrown:

SELECT fw.category_id categoryId,fw.user_id userId,u.username,fw.moderator_order moderatorOrder,fw.newInheritedmod FROM jforum_forums_watch fw INNER JOIN jforum_users u ON u.user_id=fw.user_id WHERE fw.category_id=1 AND fw.forum_id=0order by moderatorOrder asc
 ... 47 more
12:02:34,437 ERROR [ExceptionWriter     ]
Method public java.util.List net.jforum.entities.Category.getSuperModeratorList() threw an exception when invoked on [Category Test, id=1, order=1]
The problematic instruction:
----------
==> assignment: moderators=category.getSuperModeratorList() [on line 45, column 25 in default/admin/forum_moderator.htm]
----------

Java backtrace for programmers:
----------
freemarker.template.TemplateModelException: Method public java.util.List net.jforum.entities.Category.getSuperModeratorList() threw an exception when invoked on [Category Test, id=1, order=1]
 at freemarker.ext.beans.SimpleMethodModel.exec(SimpleMethodModel.java:136)
 at ……
 ... 47 more
错误原因:SQL语句语法错误,引发异常。
解决方法:检查SQL语句语法是否错误,检查SQL语句列名是否错误。是否在generic_queries.sql中结尾符”/”与表名或列名挨着了,如果挨着了,那就会引发SQL语句错误,因为“/”是在generic_queries.sql中是字符串连接符。

 

错误信息6:
An error has occurred.
For detailed error information, please see the HTML source code, and contact the forum Administrator.
java.lang.NullPointerException

报错信息:空值异常。
解决方法:仔细查找某个变量的值是否出现了空值null,从而引发空值异常。
注:Freemarker不允许有null值出现。

 

错误信息7:
00:09:49,921 ERROR [ExceptionWriter     ] net.jforum.exceptions.ForumException: java.lang.reflect.InvocationTargetException
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 at java.lang.reflect.Method.invoke(Method.java:597)
 at net.jforum.Command.process(Command.java:114)
 at net.jforum.JForum.processCommand(JForum.java:217)
 at net.jforum.JForum.service(JForum.java:200)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
 ……
 ... 23 more
Caused by: net.jforum.exceptions.DatabaseException: com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ':topic:)' at line 1

Query being executed when exception was thrown:

UPDATE jforum_topics SET highlight=3 WHERE id in(:topic:)
 at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:936)
 at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2870)
 at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1573)
 at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1665)
 at com.mysql.jdbc.Connection.execSQL(Connection.java:3124)
 at ……
 ... 23 more
Caused by: com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ':topic:)' at line 1

Query being executed when exception was thrown:

UPDATE jforum_topics SET highlight=3 WHERE id in(:topic:)
 ... 35 more

URL is: /jforum/jforum.page?null
2010-4-14 0:09:51 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet jforum threw exception
java.lang.OutOfMemoryError: PermGen space
 at java.lang.ClassLoader.defineClass1(Native Method)
 at java.lang.ClassLoader.defineClass(ClassLoader.java:621)
 at ……
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)

错误原因:频繁操作导致数据库链接发生冲突。
解决方法:关闭服务器,重启服务器。

 

错误信息8:
An error has occurred.
For detailed error information, please see the HTML source code, and contact the forum Administrator.
java.sql.SQLException: SQL String can not be NULL

错误代码:
String sql=SystemGlobals.getSql("TopicModel.setTopicHighlight");
   sql.replaceAll(":topic:", this.buildInClause(topicIds));
   p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("TopicModel.updateTopicHighlight"));
   p.setInt(1, highlight);
   p.executeUpdate();
正确代码:
 String sql=SystemGlobals.getSql("TopicModel.setTopicHighlight");
   sql=sql.replaceAll(":topic:", this.buildInClause(topicIds));
   p = JForumExecutionContext.getConnection().prepareStatement(sql);
   p.setInt(1, highlight);
   p.executeUpdate();


错误信息9:
Tomcat:IOException while loading persisted sessions: java.io.EOFException
Tomcat:IOException while loading persisted sessions: java.io.EOFException
Tomcat:IOException while loading persisted sessions: java.io.EOFException

一直用tomcat一段时间都正常无事,最近一次启动tomcat就发生以下异常:

严重: IOException while loading persisted sessions: java.io.EOFException
严重: Exception loading sessions from persistent storage

原因是tomcat对硬盘的session读取失败,彻底解决办法一下:将work下面的文件清空,主要是*.ser文件,或者只是删除掉session.ser即可以解决。

解决办法是:删除这个文件就可以了。
D:/Program Files/Apache Software Foundation/Tomcat 6.0/work/Catalina/localhost/_/SESSIONS.ser

 

15:51:49,406 ERROR [ExceptionWriter     ] net.jforum.exceptions.TemplateNotFoundException: Template for action editSave is not defined
 at net.jforum.Command.process(Command.java:137)
 at net.jforum.view.admin.AdminCommand.process(AdminCommand.java:64)
 at net.jforum.JForum.processCommand(JForum.java:217)
 at net.jforum.JForum.service(JForum.java:200)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

错误原因:action中某个方法没有执行跳转页面而导致报错。

 

错误信息10:
15:07:16,901 ERROR [ExceptionWriter     ]
Expression topic.postedBy.username is undefined on line 175, column 165 in default/post_operate.htm.
The problematic instruction:
----------
==> ${topic.postedBy.username} [on line 175, column 163 in default/post_operate.htm]
----------

Java backtrace for programmers:
----------
freemarker.core.InvalidReferenceException: Expression topic.postedBy.username is undefined on line 175, column 165 in default/post_operate.htm.
 at freemarker.core.TemplateObject.assertNonNull(TemplateObject.java:124)
 ……
URL is: /jforum/jforum.page?null

解决方法:Topic对象中某个属性没有赋值

 

错误信息11
An error has occurred.
For detailed error information, please see the HTML source code, and contact the forum Administrator.
com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException: Column 'topic_id' in where clause is ambiguous

Query being executed when exception was thrown:

SELECT t.*, p.user_id AS last_user_id, p.post_time, p.attach AS attach FROM jforum_topics t, jforum_posts p WHERE p.post_id = t.topic_last_post_id AND topic_id in (253,252,242,220,147)

分析原因:列'topic_id'在where子句是模糊的


错误信息12:
An error has occurred.
For detailed error information, please see the HTML source code, and contact the forum Administrator.
java.lang.UnsupportedOperationException

 
错误原因:找不到指定action中的指定方法。

 

错误信息13

An error has occurred.
For detailed error information, please see the HTML source code, and contact the forum Administrator.
java.sql.SQLException: Parameter index out of range (3  number of parameters, which is 2).
 
原SQL语句:
TopicModel.selectAllByForumByLimit = SELECT t.*, p.user_id AS last_user_id, p.post_time, p.attach AS attach /
 FROM jforum_topics t, jforum_posts p,jforum_forums f/
 WHERE (t.forum_id = ? OR t.topic_moved_id = ? ) /
 AND p.post_id = t.topic_last_post_id /
 AND p.forum_id=f.forum_id
 AND p.need_moderate = 0 /
 or t.istop=3
 or (f.categories_id=? and t.istop=2)
 or t.topic_type=2
 ORDER BY t.topic_type DESC,t.istop DESC,t.displayorder DESC, t.topic_last_post_id DESC /
 LIMIT ?, ?
输出Sql语句不全:SELECT t.*, p.user_id AS last_user_id, p.post_time, p.attach AS attach FROM jforum_topics t, jforum_posts p,jforum_forums fWHERE (t.forum_id = ? OR t.topic_moved_id = ? ) AND p.post_id = t.topic_last_post_id AND p.forum_id=f.forum_id

错误原因:

少了“/”引发,“/” 在generic_queries.sql中相当于SQL语句连接符,少了它,可能你换行的SQL语句将不会被连接执行!
多加注意呀!~~


错误信息14:
Expression forum.forumList is undefined on line 123, column 27 in default/forum_list.htm.

有时候经常出现这种信息,自己明明在forum实体对象里定义了forumList属性,但为什么页面使用这个属性时却报未定义此属性的异常信息,本人用的CDE是MyEclipse,服务器是Tomcat,我在Tomcat服务器下的conf/server.xml里配置了如下代码:
<Context path="/jforum" docBase="F:/Workspaces/MyEclipse 8.x/jforum/WebRoot" reloadable="true" />
这行代码可实现在修改代码之后,tomcat自动重启服务,从而减少我们手动重启tomcat服务器的时间,但有时候不好使就会出现以上现象,出现这种现象的唯一解决方法就是重新发布项目重启服务,从而解决此问题!

 

错误信息15
An error has occurred.

For detailed error information, please see the HTML source code, and contact the forum Administrator.

java.lang.NumberFormatException: null

分析原因:在用request.getParameter()无法获取指定页面控件的值而导致的!

 

错误信息16:
For detailed error information, please see the HTML source code, and contact the forum Administrator.
Expression forum.name is undefined on line 110, column 158 in default/admin/forum_form.htm.

分析原因:
先看看报错的代码吧(注:此代码是jforum的源码):
for (Iterator iter = c.getForums().iterator(); iter.hasNext(); ) {
 this.addForum(new Forum((Forum)iter.next()));
}
分析:this.addForum(new Forum((Forum)iter.next()));此代码中用(Forum)iter.next()获得一个Forum对象,但又用new Forum((Forum)iter.next);来重新构造一个对象,不知道作者的用意,但此对象的属性值与获得的对象值发生了变化(注:我在数据库中对应此对象的表添加了几列,列的类型的有的是varchar型的,有的是int型的,我设置了varchar型字段的默认值为’’,设置int型字段默认值为0),在此对象的字符串类型的属性的值对应数据库中表的列的默认值设置为””的,但经过new Forum((Forum)iter.next);代码后,字符串类型的属性的值变为null了,页面获取此字符串类型属性的值为null,引发以上异常(注:页面用到了Freemarker,Freemarker不允许有null值出现)。
解决方法:只能把以上代码换成一下代码:
for (Iterator iter = c.getForums().iterator(); iter.hasNext(); ) {
 this.addForum(new Forum((Forum)iter.next()));
}

相比较:去掉了new Forum()代码,让字符串类型的属性允许有默认的””值,从解决以上出现的问题。

 

错误信息17
10:03:19,872 ERROR [ExceptionWriter     ] net.jforum.exceptions.ForumException: freemarker.core.ParseException: Found unexpected directive: <#else> on line 136, column 126
Check whether you have a well-formed if-else block.

分析原因:由于页面<#if></#if>里出现了两个<#else>而导致报以上错误信息。

 

错误信息18
An error has occurred.
For detailed error information, please see the HTML source code, and contact the forum Administrator.
java.sql.SQLException: Subquery returns more than 1 row

Query being executed when exception was thrown:

DELETE  FROM jforum_role_values WHERE role_id=(SELECT role_id FROM jforum_roles WHERE NAME='perm_forum' AND group_id not in(4,3,2)) AND role_value=30

分析原因:由于“WHERE role_id=(SELECT role_id FROM jforum_roles WHERE NAME='perm_forum' AND group_id not in(4,3,2))”中” SELECT role_id FROM jforum_roles WHERE NAME='perm_forum' AND group_id not in(4,3,2)”查询语句查询出来的是一个集合,role_id不能用”=”去接值。

 

错误信息19

An error has occurred.
For detailed error information, please see the HTML source code, and contact the forum Administrator.
java.util.NoSuchElementException

分析原因:
用iterator迭代时,多用了一次iter.next(),从而导致报以上错误信息。

错误代码:
for (Iterator iter = c.getForums().iterator(); iter.hasNext(); ) {
   Forum f=((Forum)iter.next());
   //this.addForum(new Forum((Forum)iter.next()));
   //由于new已对象的时候会默认把字符串为''的属性的值替换为null,所以在此替换
   this.addForum(f);
  }
分析:以上代码中的“//this.addForum(new Forum((Forum)iter.next()));” 已是注释掉了的代码,
但程序还是走了这个代码,从而引发以上异常,最后我把此代码去了变成一下代码
正确代码:
for (Iterator iter = c.getForums().iterator(); iter.hasNext(); ) {
   Forum f=((Forum)iter.next());
   //由于new已对象的时候会默认把字符串为''的属性的值替换为null,所以在此替换
   this.addForum(f);
  }

相比以上代码就是多了一行注释掉的“//this.addForum(new Forum((Forum)iter.next()));”代码,
程序执行了此注释掉的代码,从而引发异常,以前没遇见过这种问题。

 

注:如需转载,请注明出处,以上有什么问题解答不对,欢迎交流解答!Email:denghuafeng@live.cn

原创粉丝点击