SSH中的error解决
来源:互联网 发布:千与千寻 知乎 编辑:程序博客网 时间:2024/05/18 01:31
1 org.hibernate.PropertyNotFoundException: Could not find a getter for admin adminId in class Xxx.
首先解析一下这个错误“在类Xxx中没有找到 admin adminId”。
原因:在SQL Server 中不小心把adminId写成了adminadminId,导致在用Myeclipse反向工程时,.hbm.xml映射文件中id为Xxx的类的属性名写错,与model中的getXxx方法不相匹配。
2 struts中的action的class要与applicationContext中的Bean的id 相对应,而不是完整的类名。
参考网站:CSDN
3 Caused by: Action class [login] not found
严重: Exception starting filter struts2
Unable to load configuration. - action - file:/D:/workspace/Ecplipse/.metadata/.plugins/org.eclipse.wst.server.core/tmp1/wtpwebapps/GoogleMapFWZJW/WEB-INF/classes/struts.xml:7:38
at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:58)
at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:360)
at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:403)
。。。。。。。
Caused by: Action class [login] not found - action - file:/D:/workspace/Ecplipse/.metadata/.plugins/org.eclipse.wst.server.core/tmp1/wtpwebapps/GoogleMapFWZJW/WEB-INF/classes/struts.xml:7:38
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.verifyAction(XmlConfigurationProvider.java:405)
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.addAction(XmlConfigurationProvider.java:355)
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.addPackage(XmlConfigurationProvider.java:460)
对应的struts.xml文件如下:
<struts>
<package name="example" namespace="" extends="struts-default">
<action name="Login" class="login">
<result>/loginResult.jsp</result>
<result name="input">/login.jsp</result>
</action>
</package>
</struts>
其中的class=“login”的login对应spring的applicationContext.xml里的id为login的bean。
如果你的struts.xml和applicationContext.xml都配置正确,还报以上的错误,那么可以判断你的项目缺少jar包:struts2-spring-plugin-2.0.11.1.jar、commons-fileupload-1.2.1.jar和commons-io-1.3.2.jar
导入这些jar包就行了,这些jar可以在struts-2.1.6的lib下找到。
小编原因是没有导入struts2-spring-plugin-2.0.11.1.jar,该 jar包可以在CSDN下载 不需要积分处下载。参考文章:博客园
4 error : java.lang.NoSuchMethodError: antlr.collections.AST.getLine()I
!!!这是一个让小编调了27个小时的Bug。。。
5 Line:209-com/opensymphony/xwork2/spring/SpingObjectFactory.java:209:-1
Line: 209 - com/opensymphony/xwork2/spring/SpringObjectFactory.java:209:-1
原因两个:
1.lib中多导入包的大原因:去掉struts2-spring-plugin-2.1.8包即可,因为没有用到spring。
2.还有的原因是用spring了,却没加监听器,在web.xml里面加上
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext*.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
参考网站:网易博客
6 org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'TeacherDao' is defined
7 org.hibernate.QueryException: could not resolve property: userTypeId of: com.tcm.model.User [from com.tcm.model.User as model where model.userTypeId= ?]
+ propertyName + "=?";
8 org.hibernate.exception.SQLGrammarException: could not execute query
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: 关键字 'User' 附近有语法错误。2.user.hbm.xml 修改为table="[user]"
9 sessionFactory' is not writable or has an invalid setter method.
10 Illegal attempt to associate a collection with two open sessions
11 使用delete方法之后,没出异常但也没把数据库中的数据删去
12 使用xxxDAO.findById()查不到数据
13 java.lang.NoSuchMethodException: com.student.action.ManageStudentAction.getUnSelectedCourse()
14 org.hibernate.PropertyValueException: not-null property references a null or transient value: com.tcm.model.Admin.users
Admin.hbm.xml:
"assigned"表示:在插入数据的时候主键由用户自己添加,hibernate也不管。所以在向数据库中插入Admin之前,我们要对admin的userId人为地进行赋值。
关于主键生成策略的参考文章:Linux公社-Linux系统门户网站
(4)Service中插入功能的代码:
public String registNewAdmin(String loginName, String password,String userName, String telephone, int userTypeId, int departmentNo) {// TODO Auto-generated method stubList users_list = null;users_list = usersDAO.findByProperty("loginName", loginName);if (users_list != null && users_list.size() >= 1)return "用户名已存在";else{//先插入UserUsers users = new Users();users.setLoginName(loginName);users.setPassword(password);users.setUserType(new UserType(1));users.setUserName(userName);users.setTelephone(telephone);//System.out.println("登录名 : " + loginName);//System.out.println("登录名2:" + users.getLoginName());usersDAO.save(users);users_list = usersDAO.findByProperty("loginName", loginName);users = (Users) users_list.get(0);//System.out.println("ID = " + users.getUserId());Department department = null;List department_list = null;department_list = departmentDAO.findByProperty("departmentNo",departmentNo);if (department_list == null || department_list.size() <= 0)return "院系编码错误";department = (Department) department_list.get(0);Admin admin = new Admin();admin.setUserId(users.getUserId());admin.setLoginName(users.getLoginName());admin.setPassword(users.getPassword());admin.setUserName(users.getUserName());admin.setUserTypeId(users.getUserType().getUserTypeId());admin.setTelephone(users.getTelephone());admin.setUsers(users);admin.setDepartment(department);adminDAO.save(admin);}return "";}在上面的代码中注意三个地方:
A:在向数据库的子类表(Admin)中插入记录之前,必须保证父类表(Users)中含有相应的记录,若父类表(Users)中没有,要先向父类表(Users)中插入数据。
B:子类表中要显示设置的属性包括:从父类中继承的所有属性(包括父类的主键userId),子类Model中的父类实例(private Users users)。(感觉userId设置了两遍,可都不能缺少,不知道为什么),如下图:
注意:
admin.setUsers(users);一句中的uses是从数据库中取出的,包含了数据库(或hibernate)赋予的userId的值:
(5)DAO中向数据库中插入记录的代码:
好了,这就算完成了。增设一个userId确实是不得已的办法,若有更好的办法,请留言评论,不胜感激。
16 从JSP向Aciton传汉字时,传到Action中就变成了乱码
if(personName.equals(new String(personName.getBytes("GB2312"), "GB2312"))){ personName = new String(personName.getBytes("GB2312"),"utf-8"); }else if(personName.equals(new String(personName.getBytes("iso-8859-1"), "iso-8859-1"))){ personName = new String(personName.getBytes("iso-8859-1"),"utf-8"); }else if(personName.equals(new String(personName.getBytes("UTF-8"), "UTF-8"))){ personName = new String(personName.getBytes("UTF-8"),"utf-8"); }else if(personName.equals(new String(personName.getBytes("GBK"), "GBK"))){ personName = new String(personName.getBytes("GBK"),"utf-8"); }
小编的Action中有一变量String personName,在从JSP传到Action中后,先进行上面的处理,然后再使用personName。
public String modifyTeacher() {try {if(personName.equals(new String(personName.getBytes("GB2312"), "GB2312"))){ personName = new String(personName.getBytes("GB2312"),"utf-8"); }else if(personName.equals(new String(personName.getBytes("iso-8859-1"), "iso-8859-1"))){ personName = new String(personName.getBytes("iso-8859-1"),"utf-8"); }else if(personName.equals(new String(personName.getBytes("UTF-8"), "UTF-8"))){ personName = new String(personName.getBytes("UTF-8"),"utf-8"); }else if(personName.equals(new String(personName.getBytes("GBK"), "GBK"))){ personName = new String(personName.getBytes("GBK"),"utf-8"); } System.out.println("action personName = " + personName);if (manageAdminIService.modifyTeacher(loginName, password,userName, personName, sexName, personAge, telephone,teacherNum, departmentName)) {request.setAttribute("modifyTeacher_result", "success");} else {request.setAttribute("modifyTeacher_result", "error");}return "modifyTeacher_success";} catch (Exception e) {// TODO: handle exceptione.printStackTrace();request.setAttribute("result", "error");return ERROR;}}
参考网站:CSDN博客
17 jsp退出系统如何清除session
<body> <% session.invalidate(); response.sendRedirect("index.jsp"); %> </body>点击链接跳转到该页面。
18 错误名称:Batch update returned unexpected row count from update [0]
19 错误名称 : could not initialize proxy - no Session
20 错误名称:Invalid property 'sessionFactory' of bean class
21 关键词 hibernate LazyInitializationException collectionsession Set size()
at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationExceptionIfNotConnected(
at org.hibernate.collection.AbstractPersistentCollection.readSize(AbstractPersistentCollection.java:119)
at org.hibernate.collection.PersistentSet.size(PersistentSet.java:162)
<set name="orderforms" inverse="true"> <key> <column name="user_Id" /> </key> <one-to-many class="sdkd.com.eb.model.Orderform" /> </set>将set 元素的lazy属性设置为false。
22 org.hibernate.LazyInitializationException: could not initialize proxy - no Session
at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:132)at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:174)
at org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.invoke(JavassistLazyInitializer.java:190)
at sdkd.com.eb.model.Orderstate_$$_javassist_5.getStateName(Orderstate_$$_javassist_5.java)
简单理解就是因为,你使用了lazy=true,这样hibernate在从数据库中调数据的时候是不会把关联的对象查出来的,而是保存一个获取值得方法,在你使用getXXX()调用的时候,hiberante会利用这个保存的方法去从数据库中取数据。而往往我们在jsp页面中使用getXXX()准备展示数据的时候,session早已经在dao中就关闭了,我们该如何解决这种异常呢?
解决方法:
把lazy设成false,最2的办法,但是最简单,简单就是美嘛,也依然会有很多再使用这个方式再解决类似问题。
23 Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'orderstate0_.order_Id' in 'field list'
24 采用Hinernate 操作数据库时,如何才能使数据库表中某些字段的默认值生效?
25 $.ajax访问SSH中的Action访问不到,原因是访问的url错误
- SSH中的error解决
- 解决SSH框架整合中的 Error applying BeanValidation relational constraints错误
- python paramiko Error reading SSH protocol banner问题的解决
- ssh error
- Linux中的SSH终端乱码问题的解决
- [总结]使用ssh架构服务器uri中的中文乱码解决
- Linux中的SSH终端乱码问题的解决
- Java SSH 集成框架开发中的错误解决
- 解决ssh中的”Connection closed by 10.0.0.21“问题
- 【解决】SSH问题(6)Error configuring application listener of class org.springframework.web.context
- win7怎么创建SSH key链接github仓库,解决:git error: couldn't connect to host
- ERROR解决
- 解决ERROR
- SSH remote connect error
- SSH整合error
- 解决cygwin中的 syntax error near unexpected token问题
- 解决PHP中的Fatal error: Call to undefined function curl_init()
- 解决 vs 出现Error MC3000 给定编码中的字符无效
- margin重叠的问题
- CSS3动画和animae.css动画库的使用
- ViewStub用法
- 真机调试报 App installation failed
- android SDK生成工程文件
- SSH中的error解决
- Selenium Webdriver元素定位的八种常用方式
- ARM中的---汇编指令
- 树莓派使用蓝牙4.0连接设备并发送指令
- Python SMTP发送遇到的一些列问题
- jQuery EasyUI使用教程之根据条件更换数据网格行背景颜色
- 修改浏览器DNS缓存时间、清除系统DNS缓存
- 阮一峰的博客
- 读书笔记《高级UNIX环境编程》