当前位置: 代码迷 >> Java Web开发 >> 用easyui时出现的有关问题 初学者一枚 需要帮助
  详细解决方案

用easyui时出现的有关问题 初学者一枚 需要帮助

热度:2108   发布时间:2016-04-10 22:31:39.0
用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}],
    [{field:'productID',title:'productID',width:80,align:'center'},
     {field:'productName',title:'productName',width:80,align:'center'},
     {field:'supplierID',title:'supplierID',width:80,align:'center'},
     {field:'categoryID',title:'categoryID',width:80,align:'center'},
     {field:'quantityPerUnit',title:'quantityPerUnit',width:80,align:'center'},
     {field:'unitPrice',title:'unitPrice',width:80,align:'center'},
     {field:'unitsInStock',title:'unitsInStock',width:80,align:'center'},
     {field:'unitsOnOrder',title:'unitsOnOrder',width:80,align:'center'},
     {field:'reorderLevel',title:'reorderLevel',width:80,align:'center'},
     {field:'discontinued',title:'discontinued',width:80,align:'center'},
     
     ]
         ]
});

});




这里面我不知道url写对了没有,到底要怎么写?

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC 
"-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" 
"http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<constant name="struts.local" value="zh_CN" />
<constant name="struts.devMode" value="false" />
<package name="project" extends="json-default">
<action name="loginAction" class="bean_LoginAction">
<result type="json">
<param name="root">easyJson</param>
</result>
<!-- <result name="ok">welcome.jsp</result>  -->
</action>

<!-- <action name="loginAction" class="bean_LoginAction" > 
  相关解决方案