日期:2014-05-17  浏览次数:21003 次

用easyui时出现的问题 菜鸟一枚 需要帮助
action:
package com.ly.action;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.sf.json.JSONObject;

import com.ly.model.Products;
import com.ly.model.User;
import com.ly.service.ProductsService;
import com.ly.service.UserService;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;


public class LoginAction extends ActionSupport {

private static final long serialVersionUID = 1L;
private String username;
private String password;
private JSONObject easyJson;
private UserService userService;
private ProductsService productsService;

@Override
public String execute() throws Exception {
if(username!=null && username.length()>0 &&
password!=null && password.length()>0){
User u=userService.find(username);
if(u==null){
this.addFieldError(username, "用户名或密码错误");
return "input";
}
if(u.getPassword().equals(password)){

ActionContext.getContext().getSession().put("NAME", u.getName());
List<Products> products=productsService.find();
Map<String, Object> map = new HashMap<String, Object>();
map.put("total", products.size());
map.put("rows", products);
easyJson = JSONObject.fromObject(map);
ActionContext.getContext().getSession().put("PRODUCTS", products);
return "ok";
}else{
this.addFieldError(password, "用户名或密码错误");
return "input";
}
}else{
return "input";
}
}


public JSONObject getEasyJson() {
return easyJson;
}


public void setEasyJson(JSONObject easyJson) {
this.easyJson = easyJson;
}


public String getUsername() {
return username;
}

public void setUsername(String username) {
this.username = username;
}

public String getPassword() {
return password;
}

public void setPassword(String password) {
this.password = password;
}

public UserService getUserService() {
return userService;
}

public void setUserService(UserService userService) {
this.userService = userService;
}

public ProductsService getProductsService() {
return productsService;
}

public void setProductsService(ProductsService productsService) {
this.productsService = productsService;
}




}


js:
$(document).ready(function() {
$('#tt').datagrid({
title : 'table',
iconCls : 'icon-ok',
nowrap : fasle,
width:800,
height:500,
rownumbers:true,
url:'project/LoginAction.action',
idField:'easyJson',
method:'post',
columns:[
    [{title:'products',colspan:10}]