怎么调试Web程序
java web项目,比如登录页面,想调试,获取到jsp页面传到action的值?
--------------------编程问答--------------------
debug呀
--------------------编程问答--------------------
引用 1 楼 scottxzj 的回复: debug呀
楼主的问题很诡异,可能不是debug这么简单!
--------------------编程问答--------------------
楼主先把你的开发环境说下。
--------------------编程问答--------------------
做了一个ssh的crud例子,登录的时候不论输入什么,都抛出异常,直接转到错误页面了,action里的部分代码如下:
29行的doLogin方法没有执行,就直接跳到36行抛异常了,从页面传到user的username和password都是正确的
--------------------编程问答--------------------
楼主 你按F5进去看看啊 可能是doLogin里面的问题 走到最里面去呀
--------------------编程问答--------------------
@dragon20121114
调试的时候进去了,但进不去,直接跳到36行的异常了
--------------------编程问答--------------------
数据库连接有问题吧 ,查询不执行可能是。
--------------------编程问答--------------------
大哥,调试的时候,你就不能把 try...catch...打开,让异常抛出来看看,到底是错什么地方了?
--------------------编程问答--------------------
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);
}
--------------------编程问答--------------------
@scottxzj,去掉try catch?
--------------------编程问答--------------------
Source not found for InvocationTargetException.<init>(Throwable) line: not available
--------------------编程问答--------------------
引用 10 楼 myphoneis8 的回复: @scottxzj,去掉try catch?
@我 我是看不到的,引用我的话 我就能看到了,
对,把try catch 弄掉,控制台会打出异常信息的。
还有你的方法有逻辑问题, 账户密码应该有唯一性 不应该得到list。
String queryString = "select u from userinfo u where u.username
= '" + username + "' and u.password ='" +password+"'";
--------------------编程问答--------------------
@scottxzj,那现在咋办
--------------------编程问答--------------------
@scottxzj,去掉了之后又走了一遍,然后就报出:
Source not found for InvocationTargetException.<init>(Throwable) line: not available
--------------------编程问答--------------------
catch里面把异常打印出来看看啊,system.out.println(e);
--------------------编程问答--------------------
@nyxiaobin123,看不到啊
现在发现userService是空的,但我在applicationContext.xml里面配置了的
--------------------编程问答--------------------
我再说一次 你@scottxzj,我是看不到的, 回复内容的下面有个引用 ,引用一下我的话,我就能看到了,
我本来想让你自己调试的,算了。异常信息不应该是一句话吧,除非你有所过滤。
看你下你的错误吧: 应该是会空指针的
1、根据你的action: private UserInfo user= new UserInfo();
你action里 this.user.getUsername 是不可能有值的。 因为你是new出来的。
private UserInfo user;
geter seter 方法生成一下,就能取到值了。
2、你后面的方法 也有问题,账户密码要唯一,不可能会得出来 list的。 判断时,有值就说明账户密码正确就可以了。
--------------------编程问答--------------------
debug,你在google中搜索“myeclipse调试web”
--------------------编程问答--------------------
Quote: 引用 17 楼 scottxzj 的回复:
我再说一次 你@scottxzj,我是看不到的, 回复内容的下面有个引用 ,引用一下我的话,我就能看到了,
我本来想让你自己调试的,算了。异常信息不应该是一句话吧,除非你有所过滤。
又改了配置呢,在解决中...
--------------------编程问答--------------------
引用 17 楼 scottxzj 的回复: 我再说一次 你@scottxzj,我是看不到的, 回复内容的下面有个引用 ,引用一下我的话,我就能看到了,
我本来想让你自己调试的,算了。异常信息不应该是一句话吧,除非你有所过滤。
看你下你的错误吧: 应该是会空指针的
1、根据你的action: private UserInfo user= new UserInfo();
你action里 this……
已经改了,也在aplicationContext里配置了,还是报空指针
--------------------编程问答--------------------
1、根据你的action: private UserInfo user= new UserInfo();
你action里 this.user.getUsername 是不可能有值的。 因为你是new出来的。
private UserInfo user;
geter seter 方法生成一下,就能取到值了。
你的action里 改了么?
--------------------编程问答--------------------
引用 21 楼 scottxzj 的回复: 1、根据你的action: private UserInfo user= new UserInfo();
你action里 this.user.getUsername 是不可能有值的。 因为你是new出来的。
private UserInfo user;
geter seter 方法生成一下,就能取到值了。
你的action里 改了么?
……
action改了,user设了getter和setter,applicationContext.xml也配了
--------------------编程问答--------------------
jsp form代码 和action 改后的代码 贴出来吧 我看看
--------------------编程问答--------------------
打断点 debug模式启动
--------------------编程问答--------------------
引用 23 楼 scottxzj 的回复: jsp form代码 和action 改后的代码 贴出来吧 我看看
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();
}
--------------------编程问答--------------------
引用 23 楼 scottxzj 的回复: jsp form代码 和action 改后的代码 贴出来吧 我看看
首页的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>
--------------------编程问答--------------------
如果你在action里用了get , set方法,是不用在application里再配置的
--------------------编程问答--------------------
UserInfo user = userInfoService.doLogin(this.user.getUsername(),this.user.getPassword()); //从数据库中查出当前登录
UserInfo userInstance= userInfoService.doLogin(user.getUsername(),user.getPassword()); 试试吧
--------------------编程问答--------------------
引用 28 楼 scottxzj 的回复: UserInfo user = userInfoService.doLogin(this.user.getUsername(),this.user.getPassword()); //从数据库中查出当前登录
UserInfo userInstance= userInfoService.doLogin(user.getUsername(),user.getPass……
实在搞不定了
--------------------编程问答--------------------
你把 try catch 打开 报错的话 会有指向的,自己应该锻炼 调错误的能力,用debug 一点点走,看看为什么报错,还有,要是不会粘重要错误信息的话,可以把错误信息全粘出来。 我白天不能上QQ 领导有限制。
--------------------编程问答--------------------
我也遇到了,他提示
java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory 少了包
--------------------编程问答--------------------
给你写一个。
先是前台
<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;
--------------------编程问答--------------------
细心点就好了,肯定是小问题。
--------------------编程问答--------------------
运行debug模式 设置断点
补充: Java , Web 开发