解决方案 »

  1.   

    html页面没有${pageContext.request.contextPath}
      

  2.   


    html页面没有${pageContext.request.contextPath}刚才又试过发现,把ip:192.168.1.101 改成localhost就可以了,但是换成ip请求就不可以,这又是为什么呢
      

  3.   

    192.168.1.101:8080这样能访问tomcat吗
      

  4.   

    可以的,在浏览器输入ip可以打开页面,在html中,请求是这样的,$.ajax({
    url:"http://192.168.1.101/test_server/user_login.action",
    type:"get",
    async:true,
    data:json,
    //{"password":"123","username":"admin"}
    success:function(data,textStatus){
    //alert(data.toString());
     
    },
    error:function(XMLHttpRequest,textStatus,errorThrown){
    alert("请求出错啦");
    }服务器可就收到发来的数据,
    但是返回给客户端,firebug是这样的
    重新载入页面以获取源代码: http://192.168.1.101/test_server/user_login.action?username=admin&password=123
      

  5.   

    http://192.168.1.101/test_server/user_login.action?username=admin&password=123firebug 可以获取数据?
      

  6.   


    public String login() throws IOException {

    System.out.println(user.getUsername()+"----"+user.getPassword());
    // 调用业务层
    User loginUser = userService.login(user);
    // 判断是否登陆成功
    if (loginUser == null) {
    // 登陆失败
    response.getWriter().write("用户不存在!");
    return "login";
    } else {
    // 登陆成功
    session.setAttribute("user", loginUser);
    System.out.println("-----------------------------------");
    System.out.println(user.getUsername()+"----"+user.getPassword());
    ActionContext.getContext().put("loginUser", loginUser);
    return "loginSUCCESS";
    }
    }
    既然用json就去掉return "loginSUCCESS";方法改成 void
    struts的xml配置文件配置成接受json
    格式的
      

  7.   

    这相当于使用struts-json插件,struts配置中还需要继承json-default