java web项目,比如登录页面,想调试,获取到jsp页面传到action的值?

解决方案 »

  1.   


    楼主的问题很诡异,可能不是debug这么简单!
      

  2.   

    做了一个ssh的crud例子,登录的时候不论输入什么,都抛出异常,直接转到错误页面了,action里的部分代码如下:
    29行的doLogin方法没有执行,就直接跳到36行抛异常了,从页面传到user的username和password都是正确的
      

  3.   

    楼主 你按F5进去看看啊  可能是doLogin里面的问题  走到最里面去呀
      

  4.   

    @dragon20121114
    调试的时候进去了,但进不去,直接跳到36行的异常了
      

  5.   


    大哥,调试的时候,你就不能把 try...catch...打开,让异常抛出来看看,到底是错什么地方了?
      

  6.   

    userService.doLogin方法的代码如下:
    public T doLogin(String username, String password) throws Exception
    {
    if (username == null || password == null)
    {
    return null;
    }

    String queryString = "select u from userinfo u where u.username
                                     = '" + username + "' and u.password = " + password;
    List<T> users = dao.getObjects(queryString);
    return users.get(0);
    }
      

  7.   

    Source not found for InvocationTargetException.<init>(Throwable) line: not available
      

  8.   


    @我   我是看不到的,引用我的话  我就能看到了,
    对,把try catch 弄掉,控制台会打出异常信息的。还有你的方法有逻辑问题, 账户密码应该有唯一性 不应该得到list。String queryString = "select u from userinfo u where u.username
                      = '" + username + "' and u.password ='" +password+"'";
      

  9.   

    @scottxzj,去掉了之后又走了一遍,然后就报出:
    Source not found for InvocationTargetException.<init>(Throwable) line: not available
      

  10.   

    catch里面把异常打印出来看看啊,system.out.println(e);
      

  11.   

    @nyxiaobin123,看不到啊
    现在发现userService是空的,但我在applicationContext.xml里面配置了的
      

  12.   

    我再说一次 你@scottxzj,我是看不到的, 回复内容的下面有个引用 ,引用一下我的话,我就能看到了,
    我本来想让你自己调试的,算了。异常信息不应该是一句话吧,除非你有所过滤。
    看你下你的错误吧: 应该是会空指针的
    1、根据你的action:  private UserInfo user= new UserInfo(); 
    你action里  this.user.getUsername 是不可能有值的。  因为你是new出来的。private UserInfo user;
    geter  seter 方法生成一下,就能取到值了。2、你后面的方法 也有问题,账户密码要唯一,不可能会得出来 list的。  判断时,有值就说明账户密码正确就可以了。
      

  13.   

    debug,你在google中搜索“myeclipse调试web”
      

  14.   

    Quote: 引用 17 楼 scottxzj 的回复:

    我再说一次 你@scottxzj,我是看不到的, 回复内容的下面有个引用 ,引用一下我的话,我就能看到了,
    我本来想让你自己调试的,算了。异常信息不应该是一句话吧,除非你有所过滤。又改了配置呢,在解决中...
      

  15.   


    已经改了,也在aplicationContext里配置了,还是报空指针
      

  16.   

    1、根据你的action:  private UserInfo user= new UserInfo(); 
    你action里  this.user.getUsername 是不可能有值的。  因为你是new出来的。private UserInfo user;
    geter  seter 方法生成一下,就能取到值了。你的action里  改了么?
      

  17.   

    action改了,user设了getter和setter,applicationContext.xml也配了
      

  18.   

    jsp  form代码  和action 改后的代码  贴出来吧   我看看
      

  19.   

    打断点  debug模式启动
      

  20.   

    action的,getter和setter已省略public class UserInfoAction extends ActionSupport
    {
    private UserInfo user; private UserInfoService<UserInfo> userInfoService; private List<UserInfo> users; private String searchText; public String doLogin() throws Exception
    {
    if (this.user.getUsername() == null || this.user.getPassword() == null)     
    return INPUT;
    try
    {
    UserInfo user = userInfoService.doLogin(this.user.getUsername(),this.user.getPassword());     //从数据库中查出当前登录的用户
    if (user != null)
    {
    ActionContext.getContext().getSession().put("userinfo", user);     //将当前用户存入session中
    return doQuery();
    } else
    return INPUT;    //查不到当前用户,转到input页面

    } catch (Exception e)
    {
    e.printStackTrace();
    return ERROR;
    }
    }

    public String doQuery()    //查询用户
    {
    searchText = getParam("queryText");
    users = userInfoService.queryUsers(searchText, UserInfo.class);   //按传入的queryText查询用户名
    return SUCCESS;
    } protected String getParam(String key)    //从ServletActionContext中取出名为"queryText"的参数的值
    {
    return ServletActionContext.getRequest().getParameter(key);
    }

    public String doAdd()
    {
    String result = "";
    try
    {
    String param = getParam("param");
    if (Integer.parseInt(param) > 0)
    {
    user.setId(0);
    userInfoService.addUser(user);
    result = doQuery();
    } else
    result = "addUser";
    } catch (Exception e)
    {
    e.printStackTrace();
    }
    return result;
    } public String doEdit()
    {
    try
    {
    int param = Integer.parseInt(getParam("param"));
    if (param == 0)
    {
    int id = Integer.parseInt(getParam("id"));
    user = userInfoService.getUser(UserInfo.class, id);
    return "editUser";
    } else if (param == 1)
    {
    userInfoService.modifyUser(user);
    }
    } catch (Exception e)
    {
    e.printStackTrace();
    }
    return doQuery();
    } public String doDelete()
    {
    try
    {
    Integer param = Integer.parseInt(getParam("id"));
    userInfoService.deleteUser(param, UserInfo.class);
    } catch (Exception e)
    {
    e.printStackTrace();
    }
    return doQuery();
    }
      

  21.   

    首页的jsp:<form action="UserInfo.action" method="post">
    <table>
    <tr>
    <td>
    username
    </td>
    <td>
    <input type="text" name="user.username" />
    </td>
    <td>
    password
    </td>
    <td>
    <input type="password" name="user.password" />
    </td>
    <td></td>
    <td colspan="2">
    <input type="submit" value="submit">
    <input type="reset" value="reset">
    </td>
    </tr>
    </table>
    </form>
      

  22.   

    如果你在action里用了get , set方法,是不用在application里再配置的
      

  23.   

    UserInfo user = userInfoService.doLogin(this.user.getUsername(),this.user.getPassword());     //从数据库中查出当前登录
    UserInfo userInstance= userInfoService.doLogin(user.getUsername(),user.getPassword());     试试吧
      

  24.   

    你把 try catch  打开   报错的话 会有指向的,自己应该锻炼 调错误的能力,用debug 一点点走,看看为什么报错,还有,要是不会粘重要错误信息的话,可以把错误信息全粘出来。 我白天不能上QQ  领导有限制。
      

  25.   

    我也遇到了,他提示
    java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory 少了包
      

  26.   

    给你写一个。
    先是前台<form action = "请求路径" methd = "post">
    帐号:
    <input type = "text" name="user.userName"/>
    密码:
    <input type = "password" name = "user.userPwd"/>
    <input type="submit" value = "登录">
    </form>后台private Users user ;
    public String user() {
    return user;
    } public void setUserName(String user) {
    this.user = user;
    }
    public String checkLogin(){
    this.user = userService.checkLogin(this.user.getUserName(),this.user.getUserPwd());
    if(this.user.getUserId > 0){
    //登录成功
    }else{
    //登录失败
    }
    }
    return this.SUCCESS;