用到的js插件:
验证表单:formvalidator4.1.1(http://www.cnblogs.com/wzmaodong/archive/2008/01/11/1034901.html,http://www.yhuan.com/forum.php)
可视化编辑器:ckeditor_3.6.2(http://ckeditor.com/)
文件管理器:CKfinder(http://ckfinder.com/)
表格排序、分页、查询:DataTables-1.7.5(http://www.datatables.net/)
已解决问题:
1.
java.lang.reflect.InvocationTargetException java.lang.NoSuchMethodError: antlr.collections.AST.getLine()I
解决方法:
antrl-2.7.6.jar和antrl-2.7.2.jar冲突,删除antrl-2.7.2.jar
antrl-2.7.2.jar版本太低,换成更新点的jar包,比如:antlr-2.7.6.jar,问题即可解决。
2.
当页面由几个frame组成时,session的获取问题
如a.jsp通过bAction跳转到c.jsp,其中c.jsp由top.jsp, right.jsp, left.jsp组成,在bAction里设置session值
HttpServletRequest request = ServletActionContext.getRequest(); request.getSession().setAttribute("user",user);
在c.jsp中的top.jsp里获取
错误方法:当不是frame组成的页面时,可行
<% User user = (User) request.getSession().getAttribute("user"); %> <%=user.getUsername()%>
解决方法:
<% User user = (User) session.getAttribute("user"); %> <%=user.getUsername()%>
究其原因是作用域问题,request<session
3.
用MyEclipse写jsp时出现some characters acnnot be mapped using "ISO-8859-1"错误
解决方法:jsp页首添加
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
4.
struts2中超链接提交表单,其中seachForm为form 的name
<a href="#
"onclick="javascript:searchForm.submit();">
注意a href=“#”而不是a href = “”
另外select里注意select里判断语句
<select style="width: 120px" name="graduateOrNot">
<option value="none" <s:if test="graduateOrNot.equals('none')">selected</s:if>>所有校友</option>
<option value="yes" <s:if test="graduateOrNot.equals('yes')">selected</s:if>>已毕业</option>
<option value="no" <s:if test="graduateOrNot.equals('no')">selected</s:if>>在读学生</option>
</select>
5.
js动态修改table内容
<html> <head> <script type="text/javascript"> function test(){ var objRows = document.getElementById("test").rows; alert("length " + objRows.length); var objCells; for(var i = 0; i < objRows.length; i ++){ objCells = objRows[i].cells; objCells[1].innerHTML = "<input type='text' value='" + objCells[1].innerHTML + "'/>" + "test"; //objCells[1].innerHTML = "test" + objCells[1].innerHTML; } } </script> </head> <body> <table id="test" border="1"> <tr> <td>第一列</td><td id="sec">第二列</td> </tr> <tr> <td>2第一列</td><td id="sec">2第二列</td> </tr> </table> <input type="button" value="test" onclick="test()"></input> </body> </html>
6.
js转义字符 “\"
var temp = "<a href=\"test.jsp\">test.jsp</a>";
7.
js动态修改表格为编辑状态后,点击保存,参数无法传入action
可能与页面的预处理有关。
解决方法:<form放的位置不对
8.
表格跨列
<td colspan="2"></td>
跨行
<tr rowspan="3"></tr>
9.
jsp显示日期格式
原显示: 12-2-27 21:16:03.000
<s:property value="postTime"/>
采用:2012-02-27 21:16:03
<s:date name="postTime" format="yyyy-MM-dd HH:mm:ss" />
10.
时间戳问题
在mysql里设计表中messageNewsAlum里的postTime字段类型为timestamp,在mysql里写插入语句,
可自动插入postTime,但问题是日期正确,小时分钟错误
另外,hibernate配置文件里.hbm.xml映射类型虽然为timestamp,但是java类里写插入语句的时候,
不能自动插入postTime,报空指针。
原:
<property name="postTime" type="java.sql.Timestamp"> <column name="postTime" length="19" not-null="true" /> </property>
后改为:http://blog.csdn.net/daryl715/article/details/1931658
<!-- timestamp标签必须跟在id标签后面 -->
<timestamp name="postTime" column="postTime"></timestamp>
这样的话,该字段在插入时自动插入当前系统时间,更新时也会将postTime更新为当前时间
若不想更新的话,解决方法:使其既不能插入也不能更新,只能使用数据库中的默认值CURRENT_TIMESTAMP
<property name="postTime" type="java.sql.Timestamp" insert="false" update="false"> <column name="postTime" length="19" not-null="true" /> </property>
另外,对于mysql数据库的navicat客户端,默认填写CURRENT_TIMESTAMP,不勾选“刷新当前时间戳记时”
sql语句
更新:
`postTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
不更新:
`postTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
11.
数据库表中某个字段设置了默认值,如messageNewsAlum表中parent字段默认设为-1
但是在java类中插入该表内容,却不设置parent值的时候,会报parent不能为空的错误
解决方法:http://hi.baidu.com/laihua2006/blog/item/241a2939dc2f39e3b211c7a2.html
.hbm.xml中添加dynamic-insert="true" dynamic-update="true"
<class name="org.com.entity.MessageNewsAlum" table="messagenewsalum" catalog="alumnus" dynamic-insert="true" dynamic-update="true">
但是问题仍然没解决,则采用如下方法:
解决方法一:
将该字段的 not-null属性设置为false,因为有默认值所以总也不会出现null的情况,所以可以设为false
方法二:http://www.blogjava.net/keweibo/articles/353872.html
添加 insert="false" update="true"即插入语句的时候不对数据库的该字段进行操作,也就保留了默认值
而更新的时候却可以改变改字段的值
<property name="parent" type="java.lang.Integer" insert="false" update="true"> <column name="parent" not-null="true" /> </property>
12.
mysql创建表时,默认使用ENGINE=MyISAM,但是这样不能创建触发器,只有改成ENGINE=InnoDB才可
如何在创建表的时候,默认使用ENGINE=InnoDB呢?
13.
合并两个表的记录,需要有相同字段,采用union为提取不重复值,若允许重复则用union all
select userIdFK, title,postTime from topic union select userIdFK, title,postTime from reply order by postTime
14.
对于从两个或多个表查询出来的List,可以建javaBean,还可以创建视图
mysql中点击创建视图:输入sql:
select m.messageNewsAlumId,m.userIdFK,m.postTime,m.title,m.content,m.state where m.type='message' from messageNewsAlum as m union select r.replyId, r.userIdFK, r.postTime,r.title,r.content,r.state from messageReply as r order by postTime desc
点击保存,注意不要写上create view as,因为mysql已经自动给加上了
然后在eclipse里写hibernate映射文件如TopicReplyView.java,TopicReplyViewId.java,TopicReplyView.hbm.xml
TopicReplyView.java
package org.com.entity; /** * Topicreplyview entity. @author MyEclipse Persistence Tools */ public class TopicReplyView implements java.io.Serializable { // Fields private TopicReplyViewId id; // Constructors /** default constructor */ public TopicReplyView() { } /** full constructor */ public TopicReplyView(TopicReplyViewId id) { this.id = id; } // Property accessors public TopicReplyViewId getId() { return this.id; } public void setId(TopicReplyViewId id) { this.id = id; } }
TopicReplyViewId.java
package org.com.entity; import java.sql.Timestamp; /** * TopicreplyviewId entity. @author MyEclipse Persistence Tools */ public class TopicReplyViewId implements java.io.Serializable { // Fields private Integer messageNewsAlumId; //private Integer userIdFk; private User user; private Timestamp postTime; private String title; private String content; private Integer state; // Constructors /** default constructor */ public TopicReplyViewId() { } /** full constructor */ public TopicReplyViewId(Integer messageNewsAlumId, User user, //Integer userIdFk, Timestamp postTime, String title, String content, Integer state) { this.messageNewsAlumId = messageNewsAlumId; //this.userIdFk = userIdFk; this.user = user; this.postTime = postTime; this.title = title; this.content = content; this.state = state; } // Property accessors public Integer getMessageNewsAlumId() { return this.messageNewsAlumId; } public void setMessageNewsAlumId(Integer messageNewsAlumId) { this.messageNewsAlumId = messageNewsAlumId; } /* public Integer getUserIdFk() { return this.userIdFk; } public void setUserIdFk(Integer userIdFk) { this.userIdFk = userIdFk; } */ public User getUser() { return user; } public void setUser(User user) { this.user = user; } public Timestamp getPostTime() { return this.postTime; } public void setPostTime(Timestamp postTime) { this.postTime = postTime; } public String getTitle() { return this.title; } public void setTitle(String title) { this.title = title; } public String getContent() { return this.content; } public void setContent(String content) { this.content = content; } public Integer getState() { return this.state; } public void setState(Integer state) { this.state = state; } public boolean equals(Object other) { if ((this == other)) return true; if ((other == null)) return false; if (!(other instanceof TopicReplyViewId)) return false; TopicReplyViewId castOther = (TopicReplyViewId) other; return ((this.getMessageNewsAlumId() == castOther .getMessageNewsAlumId()) || (this.getMessageNewsAlumId() != null && castOther.getMessageNewsAlumId() != null && this .getMessageNewsAlumId() .equals(castOther.getMessageNewsAlumId()))) // && ((this.getUserIdFk() == castOther.getUserIdFk()) || (this // .getUserIdFk() != null // && castOther.getUserIdFk() != null && this // .getUserIdFk().equals(castOther.getUserIdFk()))) && ((this.getUser() == castOther.getUser()) || (this .getUser() != null && castOther.getUser() != null && this .getUser().equals(castOther.getUser()))) && ((this.getPostTime() == castOther.getPostTime()) || (this .getPostTime() != null && castOther.getPostTime() != null && this .getPostTime().equals(castOther.getPostTime()))) && ((this.getTitle() == castOther.getTitle()) || (this .getTitle() != null && castOther.getTitle() != null && this.getTitle() .equals(castOther.getTitle()))) && ((this.getContent() == castOther.getContent()) || (this .getContent() != null && castOther.getContent() != null && this.getContent() .equals(castOther.getContent()))) && ((this.getState() == castOther.getState()) || (this .getState() != null && castOther.getState() != null && this.getState() .equals(castOther.getState()))); } public int hashCode() { int result = 17; result = 37 * result + (getMessageNewsAlumId() == null ? 0 : this .getMessageNewsAlumId().hashCode()); // result = 37 * result // + (getUserIdFk() == null ? 0 : this.getUserIdFk().hashCode()); result = 37 * result + (getUser() == null ? 0 : this.getUser().hashCode()); result = 37 * result + (getPostTime() == null ? 0 : this.getPostTime().hashCode()); result = 37 * result + (getTitle() == null ? 0 : this.getTitle().hashCode()); result = 37 * result + (getContent() == null ? 0 : this.getContent().hashCode()); result = 37 * result + (getState() == null ? 0 : this.getState().hashCode()); return result; } }
TopicReplyView.hbm.xml
<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <!-- Mapping file autogenerated by MyEclipse Persistence Tools --> <hibernate-mapping> <class name="org.com.entity.TopicReplyView" table="topicReplyView" catalog="alumnus"> <composite-id name="id" class="org.com.entity.TopicReplyViewId"> <key-property name="messageNewsAlumId" type="java.lang.Integer"> <column name="messageNewsAlumId" /> </key-property> <!-- <key-property name="userIdFk" type="java.lang.Integer"> <column name="userIdFK" /> </key-property> --> <key-many-to-one name="user" class="org.com.entity.User"> <column name="userIdFK" not-null="true" /> </key-many-to-one> <key-property name="postTime" type="java.sql.Timestamp"> <column name="postTime" length="19" /> </key-property> <key-property name="title" type="java.lang.String"> <column name="title" length="50" /> </key-property> <key-property name="content" type="java.lang.String"> <column name="content" /> </key-property> <key-property name="state" type="java.lang.Integer"> <column name="state" /> </key-property> </composite-id> </class> </hibernate-mapping>
15.
两表联合的情况下,如何知道记录来自哪个表,添加一个字段表明来自哪个表
修改select语句,增加一个字段,类似如下:
select 'A ' as 表名,... from tableA
union
select 'B ' as 表名,... from tableB
16.
struts2标签在jsp中显示index
<s:iterator value="mnaList" status="sta"> <tr> <td height="20"> <s:property value="#sta.index+1"/> </td> </tr> </s:iterator>
17.
jsp页面显示<s:property时未显示正确值:ognl.NoConversionPossible
解决方法:添加lazy="false" http://hi.baidu.com/yby0260/blog/item/f5b53ade3d68581f62279848.html
<key-many-to-one name="user" class="org.com.entity.User" lazy="false"> <column name="userIdFK" not-null="true" /> </key-many-to-one>
18.
struts2 标签 输出html代码解决方式【转】
有时候用<s:property 输出一些带有html字符的控制字符串,本意是想让它可以解析成一些功能文字,比如超链接。可是,struts会把它原样输出,这时候只需要:
HTML标签会原样输出,因为struts标签会对html进行自动的编码,并且此标签有内置属性escape。此属性默认值是true,就是它控制着是否自动编码,所以加入escape="false"就OK了
例如
<s:property value="服务器传回来的HTML字符串" escape="false"/>
19.
action调用action
参考:http://liminhappygirl.iteye.com/blog/1290340;http://blog.csdn.net/alyssa_qian/article/details/5649300
方法一:redirectAction
<result name="saveMRInfo" type="redirectAction"> <param name="actionName">messageNewsAlumAction!searchMRepInfo</param> <param name="id">${id}</param> <param name="tableName">${tableName}</param> </result>
方法二:redirect:多个参数时,需要使用"&"代替"&"
<result name="saveMRInfo" type="redirect"> messageNewsAlumAction!searchMRepInfo?id=${id}&tableName=${tableName} </result>
方法三:chain
<action name="isBankUserExist" class="com.dreamer.firstbank.action.BankUserExistAction" method="isBankUserExist"> <result name="success" type="chain">createAccount</result> </action> <action name="createAccount" class="com.dreamer.firstbank.action.CreateAccountAction" method="createAccount"> <result name="success">/staff/kaihu3.jsp</result> </action>
20.
弹出提示窗口
<script type="text/javascript"> function deleteMRInfo(){ if (confirm("删除是不可恢复的,你确认要删除吗?")){ return true; }else{ return false; } } </script>
<a href="#" onclick="javascript:return deleteMRInfo();">删除</a>
21.
Eclipse 保存文件时自动格式化代码http://xieyanhua.iteye.com/blog/1447616
22.
mysql中UNSIGNED(未签署) 修饰符规定字段只保存正值
23.
Resource is out of sync with the file system: '/emsp_oam08/WebContent/images/Thumbs.db'
http://hi.baidu.com/lynsahuang/blog/item/a3ecdd9819b7840f6f068cec.html
是文件系统不同步的问题,需要手动刷新一下资源管理器
应该按一下F5,就好了
Thumbs.db在存在大量图片的文件夹下才会产生,有时病毒也会产生,删除没有影响。
24.
jsp中用request.getParameter("")取中文时得到乱码,解决方法:
String author = new String(request.getParameter("author").getBytes("ISO8859-1"),"UTF-8");
25.
回车自动提交表单问题
http://www.blueidea.com/articleimg/2009/02/6390/submit1.html
26.
页面在两秒后跳转到index.jsp
<meta http-equiv= "refresh" content= "2;url= ../index.jsp"/>
27.
只执行action不跳转页面,使用<s:action="" executeResult="false"></s:action>貌似解决不了
笨方法 index.jsp里使用27中的方法跳转到action
<meta http-equiv= "refresh" content= "0;url= indexAction!init.action"/>
action再转到index1.jsp,这样index.jsp相当于没用了
28.
跳转页面
var url = "profileAction!addAlumBath.action?filePath=" + path; location.href= url;
29.
mysql中timestamp的时间比系统时间早8小时,即时区问题,解决方法:
show variables like '%time_zone';//查询mysql的时区设置 system_time zone | | time_zone |UTC| select now();//mysql的当前时间 set time_zone = system;//将UTC设置为system,即可得到正确时间
问题是select now();显示时间正确,而插入数据时timestamp的时间仍然不对
解决方法:修改配置文件my.ini
E:\Program Files\xampp\xampp\mysql\bin
将default-time-zone = "UTC"改为:
default-time-zone = "+8:00"
暂时未解决问题:
1. 数据库表设计的有问题:
(1)如两条jobInfo的profileId可能相同,两条profile的userId可能相同
(2)数据库表中username可以相同,只能通过前台判断不安全。。
unique
http://www.iteye.com/problems/48403
2.jsp页面中java代码片段<%%>内的值如何与前台传来的<s:property里的值进行比较
3.如何利用hibernate自动生成数据库表
如何在创建表的时候,默认使用ENGINE=InnoDB呢?
4.可视化HTML编辑器CKEditor:http://ckeditor.com/
5.cookies记住密码
6.CKfinder??上传图片时,浏览服务器有问题