struts2 ognl错误

asdf001_ 2009-10-27
OGNL出错,各位帮忙看看,谢谢!!!!
struts.xml:
<struts>
<package name="default" extends="struts-default">
<action name="login" class="com.zb.action.LoginAction">
<result name="success" type="redirect">/loginSuc.jsp</result>
<result name="input">/index.jsp</result>
</action>
</package>
</struts>

首页:
<form action="login" method="post">
姓名:
<input type="text" name="user.username">
<br>
密码:
<input type="text" name="user.password">
<br>
<input type="submit" value="登录">
</form>
loginSuc.jsp:
<body>
名字属性获取:
<s:property value="user.username" />
</body>

User.java:
public class User {
private String username;
private String password;
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;
}
}


LoginAction:
public class LoginAction extends ActionSupport {

private User user;

public User getUser() {
return user;
}

public void setUser(User user) {
this.user = user;
}

@Override
public String execute() throws Exception {
if (user.getUsername().trim().equalsIgnoreCase("aaa")
&& user.getPassword().equals("aaaaaa")) {
return SUCCESS;
} else {
return ERROR;
}
}
}
kingx67 2009-10-27
!从代码整体看是没问题,不清楚你报的什么错误。
不知道页面有没有 引入<%@ taglib prefix="s" uri="/struts-tags"%>
还有
loginSuc.jsp 页面 中
名字属性获取:
<s:property value="user.username" />
是没值的 因为你配置重定向过来的type="redirect" 。
wangzhanfeng 2009-10-28
看代码没有错误,报什么样的错误?
初出茅庐555 2009-10-28
type="redirect",无法传值代码没见有错,报什麽
eimhee 2009-10-28
没有LOG吗, 你发LOG看看
cppmayi 2009-10-29
<form action="login" method="post"> 这句是html的form吧,检测不到login.action啊

你改成<form action="login.action" method="post">

struts2的filter会判断后缀是action的发送到struts.xml找name为前台指定的name的action类,如:前台是login.action,会在struts.xml中找action name="login"对应的class


如果form采用的是struts2标签的话就不用加action后缀了


还有result的type是redirect重定向是无法取到值的,不过可以这样写

<result name="success" type="redirect">loginSuc.jsp?username=${user.username}</result>

这样前台就可以取到值了

http://cppmayi.iteye.com/blog/490883
garryyrc 2009-10-30
错误提示呢~
asdf001_ 2009-11-12
谢谢各位 ,type="redirect" 导致出错了。
weibawoaini 2009-11-19
struts2的拦截器只能拦截以“*.action”结束的url
younglibin 2009-11-23
cppmayi 写道
<form action="login" method="post"> 这句是html的form吧,检测不到login.action啊

你改成<form action="login.action" method="post">

struts2的filter会判断后缀是action的发送到struts.xml找name为前台指定的name的action类,如:前台是login.action,会在struts.xml中找action name="login"对应的class


如果form采用的是struts2标签的话就不用加action后缀了


还有result的type是redirect重定向是无法取到值的,不过可以这样写

<result name="success" type="redirect">loginSuc.jsp?username=${user.username}</result>

这样前台就可以取到值了

http://cppmayi.iteye.com/blog/490883

   




错误提示拿出来啊! 要不咋知道
Global site tag (gtag.js) - Google Analytics