- 浏览: 547400 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (740)
- css (4)
- jquery (8)
- javascript (23)
- html (0)
- uml (0)
- 设计模式 (1)
- 开发工具 (14)
- json (4)
- struts 1.x (3)
- spring (3)
- hibernate (6)
- struts 2.x (17)
- JFreechart (0)
- j2se (48)
- jsp (9)
- flex (22)
- 找工作 (1)
- 技术杂谈 (18)
- 网络编程 (5)
- io流 (1)
- ORACLE (15)
- 报表 (3)
- extjs (11)
- jpbm (2)
- swing (5)
- jspereports (3)
- sql (1)
- linux (15)
- ps (1)
- storm (4)
- hbase (8)
- li (0)
- python (1)
- hive (3)
- 机器学习 (1)
- hdfs (1)
- elasticsearch (1)
- hadoop 2.2 (5)
- hadoop (1)
最新评论
-
Tristan_S:
这个有点意思
ASM -
starryskydog:
程序修改detail band部分的样式 如内容字体大小 ...
使用jasperReport实现动态表头 -
samwong:
Good, so usefule
使用YUI Compressor压缩CSS/JS -
gc715409742:
能够告诉我怎么在web项目中使用YUI Compressor? ...
使用YUI Compressor压缩CSS/JS -
JsonTeye:
您好! 我看你的代码,我现在也在做动态报表,实现功能由用户自己 ...
使用jasperreport动态生成pdf,excel,html
今天项目中遇到了positioned update are not supported这个异常
先看源代码吧
UserAction.java
public class UserAction extends ActionSupport{
private String password;
private User user;
private String validateCode;
private Boolean success;
private String msg;
public void setUser(User user) {
this.user = user;
}
public User getUser() {
return user;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getValidateCode() {
return validateCode;
}
public void setValidateCode(String validateCode) {
this.validateCode = validateCode;
}
public Boolean getSuccess() {
return success;
}
public void setSuccess(Boolean success) {
this.success = success;
}
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
@Resource private UserService userService;
@SuppressWarnings("static-access")
public String list(){
String start = ServletActionContext.getRequest().getParameter("start");
String limit = ServletActionContext.getRequest().getParameter("limit");
Integer index = Integer.parseInt(start);
Integer pageSize = Integer.parseInt(limit);
String json = userService.convertAllUser(index,pageSize);
//输出json对象
HttpServletResponse response = ServletActionContext.getResponse();
response.setContentType("Application/json;charset=GBK");
response.setHeader("Cache-Control","no-cache");
PrintWriter out = null;
try {
out = response.getWriter();
out.print(json);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
if(out!=null){
out.flush();
out.close();
}
}
return this.SUCCESS;
}
@SuppressWarnings("static-access")
public String update(){
HttpServletRequest request = ServletActionContext.getRequest();
String jsonArray = request.getParameter("data");
userService.saveAllUsers(jsonArray);
return this.SUCCESS;
}
@SuppressWarnings("static-access")
public String delete(){
HttpServletRequest request = ServletActionContext.getRequest();
String jsonArray = request.getParameter("data");
userService.deleteAllUser(jsonArray);
return this.SUCCESS;
}
@SuppressWarnings("static-access")
public String checkUser(){
String name = ServletActionContext.getRequest().getParameter("name");
System.out.println(name);
if(name!=null){
List<User> users = userService.getUserByName(name);
System.out.println("--------------------");
System.out.println(users.size());
System.out.println("--------------------");
if(users.size()!=0){
success = true;
msg = "用户名已存在";
}else{
success = false;
msg = "用户名可以注册";
}
}
System.err.println(msg);
System.out.println(success);
return this.SUCCESS;
}
@SuppressWarnings("static-access")
public String save(){
String roleId = ServletActionContext.getRequest().getParameter("role_id");
System.out.println(roleId);
Integer role_id = Integer.parseInt(roleId);
System.out.println(user);
System.out.println(password);
System.out.println(role_id);
if(user!=null){
userService.saveUser(user,role_id);
success = true;
msg = "保存成功";
}
return this.SUCCESS;
}
@SuppressWarnings("static-access")
public String checkLogin(){
String validate = (String) ActionContext.getContext().getSession().get("validateCode");
if(validate.equals(validateCode.trim())){
String userName = user.getUserName().trim();
String psd = user.getPassword().trim();
List<User> users = userService.getUserByName(userName);
if(users.size()!=0){
User user = users.get(0);
if(user.getPassword().equals(psd)){
success = true;
msg = "登录成功";
Role role = user.getRole();
List<ACL> acls = role.getAcls();
List<UserAllInfo> userInfos = new ArrayList<UserAllInfo>();
ArrayList<Module> modules = new ArrayList<Module>();
HttpSession session = ServletActionContext.getRequest().getSession();
for(ACL acl :acls){
Module module = acl.getModule();
UserAllInfo userInfo = new UserAllInfo(module.getId(),acl.getPermission(),user.getUserName(),module.getText());
userInfos.add(userInfo);
modules.add(module);
}
session.setAttribute("user", user);
session.setAttribute("acl", acls);
session.setAttribute("role", role);
session.setAttribute("modules", modules);
session.setAttribute("userInfo", userInfos);
}
}else{
success = false;
msg = "用户名不存在";
}
}else{
success = false;
msg = "验证码错误";
}
return this.SUCCESS;
}
}
UserService.java
@Service
public class UserService {
@Resource private UserDAO userDAO;
@Resource private RoleDAO roleDAO;
public List<User> getUsers(){
return userDAO.getUsers();
}
@SuppressWarnings({ "unchecked", "deprecation" })
public void saveAllUsers(String jsonUser){
JSONArray jsonArray = JSONArray.fromObject(jsonUser);
List<User> users = JSONArray.toList(jsonArray, User.class);
for(User user :users){
if(user!=null){
userDAO.update(user);
}
}
}
public String convertAllUser(Integer index,Integer pageSize){
List<User> users = userDAO.getUsers();
List<User> subUsers = null;
int count = users.size();
if((count%pageSize)<=0){
subUsers = users.subList(0,count);
}else if((count/pageSize)>index){
subUsers = users.subList(index, pageSize);
}else{
subUsers = users.subList(((count/pageSize)*pageSize),count);
}
String json="";
PropertyFilter filter = new PropertyFilter() {
public boolean apply(Object source, String name, Object value) {
// TODO Auto-generated method stub
if(name.equals("role"))return true;
return false;
}
};
JsonConfig config = new JsonConfig();
config.setJsonPropertyFilter(filter);
if(users!=null){
json+="{root:";
json += JSONArray.fromObject(subUsers, config).toString();
json+=",totalProperty:"+count+"}";
}
return json;
}
@SuppressWarnings({ "unchecked", "deprecation" })
public void deleteAllUser(String jsonUser){
JSONArray jsonArray = JSONArray.fromObject(jsonUser);
List<User> users = JSONArray.toList(jsonArray, User.class);
for(User user :users){
int id = user.getId();
if((user!=null)&&(id!=0)){
userDAO.delete(id);
}
}
}
public void saveUser(User user,Integer role_id){
Role role = roleDAO.getRoleById(role_id);
user.setRole(role);
userDAO.save(user);
}
public List<User> getUserByName(String userName){
return userDAO.getUserByName(userName);
}
}
加红的地方是我下面要讲的地方
先说下出现这个异常的原因吧 由于Role role = roleDAO.getRoleById(role_id);在获取role对象时对象里的个别属性是延迟加载的 当中有一些对象是延迟加载的,这些对象并不是原role类中的属性,而是由cglib这个字节码生成器动态生成的对象。Hibernate在这个子类中添加了hibernateLazyInitializer等等的附加属性。由于jsonplugin并不区分类和动态生成的类,所以也会试图序列化hibernateLazyInitializer属性,从而导致出现上述的异常。
思路如下:
1、判断这个对象是否由cglib生成的。代码如下:
boolean isCreateByCGLIB = clazz.getName().indexOf("$$EnhancerByCGLIB$$") > -1 ? true : false;
如果此对象确实是由cglib生成的,那么我们取此对象的基类,这一步很关键,因为通过取得此对象的基类,我们就忽略了所有由cglib生成的跟hibernate相关的属性。
2、通过反射,取得此对象的所有继续于基类的属性。
3、通过反射,取得此对象的所有get方法器(这一步不能省,不然出来的属性就少了)。
4、输出json。
可是我们需要user的getter 和setter方法 那不能去掉这两个方法怎么办呢 那只有这样 在struts的配置文件中加一下配置
action name="user_*" class="userAction" method="{1}">
<result name="success" type="json">
<param name="excludeProperties">user</param>
</result>
</action>
在序列化action里属性时不序列化user这个属性 就可以了
发表评论
-
Exception starting filter struts2java.lang.NoClassDefFoundError: org/apache/comm
2011-10-28 08:49 1364遇到个启动Tomcat的错误。错误类型是: 严重: Ex ... -
Struts2 如何获取Request,Session对象
2010-10-19 10:34 1457Struts2 如何获取Request,Session对象 ... -
Jasperreport+ireport 实践操作及web应用
2010-08-08 09:10 1910Jasperreport+ireport 实践操 ... -
Struts2的基本流程
2010-08-03 11:17 1228Struts2的基本流程 大致上,Struts2框架由三个 ... -
动态表头
2010-08-02 23:19 1276最近在我公司drp(运营分销系统)开发中,需要大量报表,由于本 ... -
运行struts2时又出现问题了,本来是用通配符的,却出现了如下错误:
2010-08-02 18:14 1167运行struts2时又出现问题了,本来是用通配符的,却出现了如 ... -
Unable to instantiate Action(关于struts2.0异常)
2010-08-02 17:57 1591Unable to instantiate Action(关于 ... -
Jasper Report用户手册
2010-08-02 11:32 1451Jasper Report用户手册... i version1 ... -
iReport学习笔记——动态报表
2010-08-01 23:29 1735iReport学习笔记——动态报表 最近一直在研究jaspe ... -
动态生成报表
2010-08-01 22:43 1851项目里用到了jasperreport,平时都是用ireport ... -
JasperReport学习笔记2-创建简单的报表例子
2010-08-01 21:21 1922JasperReport学习笔记2-创建简单的报表例子 一, ... -
log4j error
2010-07-27 19:17 749在强调可重用组件开发的今天,除了自己从头到尾开发一个可重用的日 ... -
log4j:WARN Please initialize the log4j system properly
2010-07-27 18:49 1636log4j:WARN Please initialize th ... -
Struts2的类型转换器
2010-07-27 17:53 811Struts2的类型转换器 一、概述 在B/S应用中,将字 ... -
Struts2的常量详解
2010-07-27 17:51 758Struts2的常量详解 通常struts2加载strut ... -
Unable to load configuration
2010-07-23 09:18 1070问题解决:Unable to load configurati ...
相关推荐
MySQL驱动程序是连接Java应用程序与MySQL数据库的关键组件。在Java编程中,我们通常使用JDBC(Java Database Connectivity)API来实现这种连接。JDBC提供了一组接口和类,使得Java程序能够与各种数据库进行交互,...
Fixed Replace not working as expected in conjunction with regex look behinds Fixed build systems being unable to use "file_patterns" with the exec command Corrected tab overlap on HiDPI Windows and ...
此资源是关于移动端框架Flutter(基于Android)的一些常见组件的介绍,包括PPT讲义及源码示例。 此资源介绍的相关内容有:页面布局 Stack层叠组件、Stack与Align、Stack与Positioned实现定位布局、Flutter Aspect...
(case=5567, case=7457) 6027, 6021 Listboxes are positioned such that they are not truncated at the right edge of the screen. (case=5178) Listbox remains on the same side of a symbol (either ...
【关于div+css的用法总结】 随着网页设计技术的发展,传统的table布局方式逐渐被淘汰,取而代之的是更加灵活和可维护的div+css布局。这种布局方式强调内容与样式的分离,使得网页设计更加模块化,易于适应不同的...
is introduced and the supported shading algorithms and light types are de- scribed. Chapter 9 covers programmable vertex shading. Programmable vertex shaders can process the vertex data streams with ...
本文将深入探讨Flutter的层叠布局组件——Stack和Positioned,以及它们如何实现类似Web中的绝对定位和Android中的Frame布局。 Stack组件是Flutter中用于创建堆叠布局的一个关键工具,它允许子组件按照声明的顺序堆...
Tool tips are given in blue color. The cursor needs to be positioned on these for detailed explanation. The main file is "runsim.m". In these simulations the SISO option is not explicitly given. This...
sector, are currently requested to make a hard decision, that is, whether to adopt blockchain or not, and they will only know if they were right in 3–5 years. The objective of this paper is to ...
总结来说,"Positioned Relative To CRX"是一款增强Chrome DevTools功能的实用扩展,它增强了开发者对页面元素相对定位的理解和控制,提高了网页布局和设计的工作效率。对于任何处理CSS定位的开发者而言,这都是一个...
more than one operator can operate on an operand (because the operators are positioned next to the operand, one on either side), this operand is first processed by the operator of the higher ...
Flutter 总结及遇到的问题集合 在 Flutter 开发中,我们经常会遇到一些问题和难题,本文将总结一些常见的 Flutter 问题和解决方案,帮助开发者快速解决问题,提高开发效率。 一、环境配置 在 Flutter 开发中,...
positioned-io这个板条箱允许您指定读写偏移量,而无需更改文件中的当前位置。 这类似于preposition-io。此板条箱可让您指定读写偏移量,而无需更改文件中的当前位置。 这类似于C中的pread()和pwrite()。这种...
本项目"wifi_positioned:wifi本地化演示"是一个用Java实现的Wi-Fi定位系统演示,旨在帮助用户理解并实践Wi-Fi定位的基本原理和应用。 1. **Wi-Fi定位基础** Wi-Fi定位依赖于Wi-Fi AP的RSSI值,这些值可以反映出...
2034: Browse cursor not positioned on message.** - **含义**:浏览光标未定位在消息上。 - **解决方案**:确保浏览光标正确地定位在所需消息上。 **33. 2035: Not authorized for access.** - **含义**:访问未...
- `.position()`返回元素相对于其最近的相对定位(positioned)祖先元素的位置。 - `.scrollTop()`和`.scrollLeft()`分别获取元素的垂直和水平滚动位置。 9. **事件处理**: - 示例中的`.bind()`方法用于绑定...
The intended audience is those folks who are not computer scientists, but who enjoy computing and have always wanted to know how compilers work. A lot of compiler the- ory has been left out, but the ...
,,,,<th> tags are supported. <br/> 图片插入和自动上传 <br/>Built-in thumbnail generator. Thumbnail images are dynamically created; Supports upload new images. Paging - specify how many...
Chapter 2, Building a Mobile Layout, is where we concentrate on some fundamental processes in designing an Android interface, such as the content hierarchy and how components are positioned and scaled...