日期:2014-05-18 浏览次数:20688 次
function login(){
var url="Login_login";
var params={"id":1,"password":"110"};
//ajax()方法
jQuery.ajax({
type: "get",
async: true,
url: url,
data: params,
contentType: "application/json; charset=utf-8",
dataType: "json",
cache: false,
success: function (data) {
alert("success "+data.id);
},
error: function (err) {
alert("erro");
}
});
<package name="default" namespace="/" extends="json-default">
<action name="*_*" class="com.sanxiau.action.{1}Action"
method="{2}">
<result type="json" name="success">
<param name="incluepropeties">
result
</param>
</result>
</action>
</package>
public class UserLoginAction {
private int id;
private String password;
private boolean isSuccess;
//不用new,用spring容器提供
//private UserService userService=new UserServiceImp();过时
private UserService userService;
private ApplicationContext applicationContext=null;
private String result;
public String login(){
/*测试一下*/
System.out.println("id="+this.getId()+"password="+this.getPassword());
// applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");
// userService = (UserService) applicationContext.getBean("UserServiceImpl");
// isSuccess=userService.checkIdAndPassword(id, password);
Map<String, Comparable> map = new HashMap<String, Comparable>();
map.put("id", this.getId());
map.put("password",this.getPassword());
JSONObject obj = JSONObject.fromObject(map);
result = obj.toString();
System.out.pri