struts-config.xml
<form-beans>
<form-bean name="userFormBean" type="users.UserForm"/>
<form-bean name="registFormBean" type="users.RegistForm"/>
</form-beans>
<global-forwards>
<forward name="loginfailed" path="/error.jsp"/>
<forward name="loginsuccessed" path="/right.jsp"/>
<forward name="registfailed" path="/registerr.jsp"/>
<forward name="registsuccessed" path="/registsuc.jsp"/>
</global-forwards>
<action-mappings>
<action path="/login" type="users.LoginAction" name="userFormBean" scope="request" input="login.jsp"/>
<action path="/regist" type="users.RegistAction" name="registFormBean" scop="request" input="regist.jsp"/>
</action-mappings>
web.xml
<servlet>
<servlet-name>actionServlet</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>actionServlet</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>login.jsp</welcome-file>
</welcome-file-list>
18 个解决方案
#1
login.jsp
<form action="login.do" method="post">
USER NAME : <input size="15" name="name"><p>
PASSWORD : <input type="password" size="15" name="psw"><p>
<input type="submit" value="Login">
</form>
<a href="regist.jsp">Regist</a>
right.jsp
<%
UserForm userFormBean = (UserForm)request.getAttribute("userFormBean");
if (userFormBean != null && userFormBean.getName() != null) {
%>
<h1>
Welcome <%=userFormBean.getName()%> !
<%
} else {
%>
We don't welcome stranger !
<%}%>
</h1><br>
<a href="login.jsp">Login</a>||
<a href="regist.do">Regist</a>
<form action="login.do" method="post">
USER NAME : <input size="15" name="name"><p>
PASSWORD : <input type="password" size="15" name="psw"><p>
<input type="submit" value="Login">
</form>
<a href="regist.jsp">Regist</a>
right.jsp
<%
UserForm userFormBean = (UserForm)request.getAttribute("userFormBean");
if (userFormBean != null && userFormBean.getName() != null) {
%>
<h1>
Welcome <%=userFormBean.getName()%> !
<%
} else {
%>
We don't welcome stranger !
<%}%>
</h1><br>
<a href="login.jsp">Login</a>||
<a href="regist.do">Regist</a>
#2
regist.jsp
<form action="regist.do" method="post">
USER NAME : <input size="15" name="name"><p>
PASSWORD : <input type="password" size="15" name="psw"><p>
CONFIRM PASSWORD : <input type="password" size="15" name="cofirmPsw"><p>
<input type="submit" value="Regist">
</form>
<a href="login.jsp">Back to Login Page</a>
registsuc.jsp
<%
RegistForm registFormBean = (RegistForm)request.getAttribute("registFormBean");
if (registFormBean != null && registFormBean.getName() != null) {
%>
<h1>
Regist successed !<br>
Welcome <%=registFormBean.getName()%> !
<%} else {%>
Regist failed ! Try again !
<%}%>
</h1><br>
<a href="regist.jsp">Regist</a>||
<a href="login.jsp">login</a>
<form action="regist.do" method="post">
USER NAME : <input size="15" name="name"><p>
PASSWORD : <input type="password" size="15" name="psw"><p>
CONFIRM PASSWORD : <input type="password" size="15" name="cofirmPsw"><p>
<input type="submit" value="Regist">
</form>
<a href="login.jsp">Back to Login Page</a>
registsuc.jsp
<%
RegistForm registFormBean = (RegistForm)request.getAttribute("registFormBean");
if (registFormBean != null && registFormBean.getName() != null) {
%>
<h1>
Regist successed !<br>
Welcome <%=registFormBean.getName()%> !
<%} else {%>
Regist failed ! Try again !
<%}%>
</h1><br>
<a href="regist.jsp">Regist</a>||
<a href="login.jsp">login</a>
#3
LoginAction.java
public class LoginAction extends Action {
public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) {
UserForm userForm = (UserForm) form;
String name = userForm.getName();
String psw = userForm.getPsw();
if(name.equalsIgnoreCase("jenny") && psw.equalsIgnoreCase("hi")) {
UserLoginLog ul = new UserLoginLog();
ul.save(name, psw);
return mapping.findForward("loginsuccessed");
} else {
return mapping.findForward("loginfailed");
}
}
}
UserForm.java
public class UserForm extends ActionForm {
private String name = null;
private String psw = null;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPsw() {
return psw;
}
public void setPsw(String psw) {
this.psw = psw;
}
}
public class LoginAction extends Action {
public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) {
UserForm userForm = (UserForm) form;
String name = userForm.getName();
String psw = userForm.getPsw();
if(name.equalsIgnoreCase("jenny") && psw.equalsIgnoreCase("hi")) {
UserLoginLog ul = new UserLoginLog();
ul.save(name, psw);
return mapping.findForward("loginsuccessed");
} else {
return mapping.findForward("loginfailed");
}
}
}
UserForm.java
public class UserForm extends ActionForm {
private String name = null;
private String psw = null;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPsw() {
return psw;
}
public void setPsw(String psw) {
this.psw = psw;
}
}
#4
问题呢?
#5
RegistAction.java
public class RegistAction extends Action {
public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) {
RegistForm registForm = (RegistForm) form;
String psw = registForm.getPsw();
String confirmPsw = registForm.getCofirmPsw();
if (psw.equalsIgnoreCase(confirmPsw)) {
//**********************************
//注意这一句,不加在registsuc.jsp就取不到registFormBean,
//为什么???? 但是那个login的例子里就没有这个阿?
request.setAttribute("registFormBean", registForm);
//***************************************
return mapping.findForward("registsuccessed");
} else {
return mapping.findForward("registfailed");
}
}
}
RegistForm.java
public class RegistForm extends ActionForm {
private String name = null;
private String psw =null;
private String cofirmPsw = null;
public String getCofirmPsw() {
return cofirmPsw;
}
public void setCofirmPsw(String cofirmPsw) {
this.cofirmPsw = cofirmPsw;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPsw() {
return psw;
}
public void setPsw(String psw) {
this.psw = psw;
}
}
public class RegistAction extends Action {
public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) {
RegistForm registForm = (RegistForm) form;
String psw = registForm.getPsw();
String confirmPsw = registForm.getCofirmPsw();
if (psw.equalsIgnoreCase(confirmPsw)) {
//**********************************
//注意这一句,不加在registsuc.jsp就取不到registFormBean,
//为什么???? 但是那个login的例子里就没有这个阿?
request.setAttribute("registFormBean", registForm);
//***************************************
return mapping.findForward("registsuccessed");
} else {
return mapping.findForward("registfailed");
}
}
}
RegistForm.java
public class RegistForm extends ActionForm {
private String name = null;
private String psw =null;
private String cofirmPsw = null;
public String getCofirmPsw() {
return cofirmPsw;
}
public void setCofirmPsw(String cofirmPsw) {
this.cofirmPsw = cofirmPsw;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPsw() {
return psw;
}
public void setPsw(String psw) {
this.psw = psw;
}
}
#6
问题在六楼代码中间
#7
呵呵,好像没给出问题来哦!
#8
六楼代码中间有问题
//**********************************
//注意这一句,不加在registsuc.jsp就取不到registFormBean,
//为什么???? 但是那个login的例子里就没有这个阿?
request.setAttribute("registFormBean", registForm);
//***************************************
return mapping.findForward("registsuccessed");
//**********************************
//注意这一句,不加在registsuc.jsp就取不到registFormBean,
//为什么???? 但是那个login的例子里就没有这个阿?
request.setAttribute("registFormBean", registForm);
//***************************************
return mapping.findForward("registsuccessed");
#9
Login那个业务的代码是书上的例子
没有任何问题
我仿照那个做了个注册的regist业务
其他的都正常
就是在成功后跳转到的页面取不到前页应该传过来的数据
是一个对象,即RegistForm得实例(Login那个是UserForm)
没有任何问题
我仿照那个做了个注册的regist业务
其他的都正常
就是在成功后跳转到的页面取不到前页应该传过来的数据
是一个对象,即RegistForm得实例(Login那个是UserForm)
#10
RegistForm registForm = (RegistForm) form;
String psw = registForm.getPsw();
String confirmPsw = registForm.getCofirmPsw();
把psw,confirmPsw打出来看看结果~~~看看这两个字符串是什么~~~
System.out.println("psw = "+psw+" confirmPsw = " + confirmPsw);
String psw = registForm.getPsw();
String confirmPsw = registForm.getCofirmPsw();
把psw,confirmPsw打出来看看结果~~~看看这两个字符串是什么~~~
System.out.println("psw = "+psw+" confirmPsw = " + confirmPsw);
#11
在java文件里利用Debug追踪的时候都是正确的
也能跳转到成功页(registsuc.jsp)
但是在registsuc.jsp中 registFormBean == null 这个判断结果是true
也能跳转到成功页(registsuc.jsp)
但是在registsuc.jsp中 registFormBean == null 这个判断结果是true
#12
<action path="/regist" type="users.RegistAction" name="registFormBean" scop="request" input="regist.jsp"/>里的input页是表单验证失败返回的页,当然不能取到值了~~~~
这么些试试
<action path="/regist" type="users.RegistAction" name="registFormBean" scop="request">
<forward id="registsuccessed" path="regist.jsp"/>
</action>
学习框架要搞清楚它的原理和流程~~~
这么些试试
<action path="/regist" type="users.RegistAction" name="registFormBean" scop="request">
<forward id="registsuccessed" path="regist.jsp"/>
</action>
学习框架要搞清楚它的原理和流程~~~
#13
先谢谢一直关注
为什么Login这么些就能取到呢?
<action path="/login" type="users.LoginAction" name="userFormBean" scope="request" input="login.jsp"/>
为什么Login这么些就能取到呢?
<action path="/login" type="users.LoginAction" name="userFormBean" scope="request" input="login.jsp"/>
#14
另外,你上面的那个还是不好用
#15
request.setAttribute("registFormBean", registForm);
你确定这句执行了么?
你确定这句执行了么?
#16
或者你把registsuc.jsp里的
<%
RegistForm registFormBean = (RegistForm)request.getAttribute("registFormBean");
if (registFormBean != null && registFormBean.getName() != null) {
%>
<h1>
Regist successed !<br>
Welcome <%=registFormBean.getName()%> !
<%} else {%>
Regist failed ! Try again !
<%}%>这段换成 ${registFormBean.name}试试
<%
RegistForm registFormBean = (RegistForm)request.getAttribute("registFormBean");
if (registFormBean != null && registFormBean.getName() != null) {
%>
<h1>
Regist successed !<br>
Welcome <%=registFormBean.getName()%> !
<%} else {%>
Regist failed ! Try again !
<%}%>这段换成 ${registFormBean.name}试试
#17
<action path="/regist" type="users.RegistAction" name="registFormBean" scop="request" input="regist.jsp"/>
总算明白你的意思了,你的代码是直接粘贴过来的么??scop写错了,应该是scope,找疯了,细心点啊
总算明白你的意思了,你的代码是直接粘贴过来的么??scop写错了,应该是scope,找疯了,细心点啊
#18
谢谢了
我找了两天了
我都疯了
谢谢了
结贴给分了
我找了两天了
我都疯了
谢谢了
结贴给分了
#1
login.jsp
<form action="login.do" method="post">
USER NAME : <input size="15" name="name"><p>
PASSWORD : <input type="password" size="15" name="psw"><p>
<input type="submit" value="Login">
</form>
<a href="regist.jsp">Regist</a>
right.jsp
<%
UserForm userFormBean = (UserForm)request.getAttribute("userFormBean");
if (userFormBean != null && userFormBean.getName() != null) {
%>
<h1>
Welcome <%=userFormBean.getName()%> !
<%
} else {
%>
We don't welcome stranger !
<%}%>
</h1><br>
<a href="login.jsp">Login</a>||
<a href="regist.do">Regist</a>
<form action="login.do" method="post">
USER NAME : <input size="15" name="name"><p>
PASSWORD : <input type="password" size="15" name="psw"><p>
<input type="submit" value="Login">
</form>
<a href="regist.jsp">Regist</a>
right.jsp
<%
UserForm userFormBean = (UserForm)request.getAttribute("userFormBean");
if (userFormBean != null && userFormBean.getName() != null) {
%>
<h1>
Welcome <%=userFormBean.getName()%> !
<%
} else {
%>
We don't welcome stranger !
<%}%>
</h1><br>
<a href="login.jsp">Login</a>||
<a href="regist.do">Regist</a>
#2
regist.jsp
<form action="regist.do" method="post">
USER NAME : <input size="15" name="name"><p>
PASSWORD : <input type="password" size="15" name="psw"><p>
CONFIRM PASSWORD : <input type="password" size="15" name="cofirmPsw"><p>
<input type="submit" value="Regist">
</form>
<a href="login.jsp">Back to Login Page</a>
registsuc.jsp
<%
RegistForm registFormBean = (RegistForm)request.getAttribute("registFormBean");
if (registFormBean != null && registFormBean.getName() != null) {
%>
<h1>
Regist successed !<br>
Welcome <%=registFormBean.getName()%> !
<%} else {%>
Regist failed ! Try again !
<%}%>
</h1><br>
<a href="regist.jsp">Regist</a>||
<a href="login.jsp">login</a>
<form action="regist.do" method="post">
USER NAME : <input size="15" name="name"><p>
PASSWORD : <input type="password" size="15" name="psw"><p>
CONFIRM PASSWORD : <input type="password" size="15" name="cofirmPsw"><p>
<input type="submit" value="Regist">
</form>
<a href="login.jsp">Back to Login Page</a>
registsuc.jsp
<%
RegistForm registFormBean = (RegistForm)request.getAttribute("registFormBean");
if (registFormBean != null && registFormBean.getName() != null) {
%>
<h1>
Regist successed !<br>
Welcome <%=registFormBean.getName()%> !
<%} else {%>
Regist failed ! Try again !
<%}%>
</h1><br>
<a href="regist.jsp">Regist</a>||
<a href="login.jsp">login</a>
#3
LoginAction.java
public class LoginAction extends Action {
public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) {
UserForm userForm = (UserForm) form;
String name = userForm.getName();
String psw = userForm.getPsw();
if(name.equalsIgnoreCase("jenny") && psw.equalsIgnoreCase("hi")) {
UserLoginLog ul = new UserLoginLog();
ul.save(name, psw);
return mapping.findForward("loginsuccessed");
} else {
return mapping.findForward("loginfailed");
}
}
}
UserForm.java
public class UserForm extends ActionForm {
private String name = null;
private String psw = null;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPsw() {
return psw;
}
public void setPsw(String psw) {
this.psw = psw;
}
}
public class LoginAction extends Action {
public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) {
UserForm userForm = (UserForm) form;
String name = userForm.getName();
String psw = userForm.getPsw();
if(name.equalsIgnoreCase("jenny") && psw.equalsIgnoreCase("hi")) {
UserLoginLog ul = new UserLoginLog();
ul.save(name, psw);
return mapping.findForward("loginsuccessed");
} else {
return mapping.findForward("loginfailed");
}
}
}
UserForm.java
public class UserForm extends ActionForm {
private String name = null;
private String psw = null;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPsw() {
return psw;
}
public void setPsw(String psw) {
this.psw = psw;
}
}
#4
问题呢?
#5
RegistAction.java
public class RegistAction extends Action {
public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) {
RegistForm registForm = (RegistForm) form;
String psw = registForm.getPsw();
String confirmPsw = registForm.getCofirmPsw();
if (psw.equalsIgnoreCase(confirmPsw)) {
//**********************************
//注意这一句,不加在registsuc.jsp就取不到registFormBean,
//为什么???? 但是那个login的例子里就没有这个阿?
request.setAttribute("registFormBean", registForm);
//***************************************
return mapping.findForward("registsuccessed");
} else {
return mapping.findForward("registfailed");
}
}
}
RegistForm.java
public class RegistForm extends ActionForm {
private String name = null;
private String psw =null;
private String cofirmPsw = null;
public String getCofirmPsw() {
return cofirmPsw;
}
public void setCofirmPsw(String cofirmPsw) {
this.cofirmPsw = cofirmPsw;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPsw() {
return psw;
}
public void setPsw(String psw) {
this.psw = psw;
}
}
public class RegistAction extends Action {
public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) {
RegistForm registForm = (RegistForm) form;
String psw = registForm.getPsw();
String confirmPsw = registForm.getCofirmPsw();
if (psw.equalsIgnoreCase(confirmPsw)) {
//**********************************
//注意这一句,不加在registsuc.jsp就取不到registFormBean,
//为什么???? 但是那个login的例子里就没有这个阿?
request.setAttribute("registFormBean", registForm);
//***************************************
return mapping.findForward("registsuccessed");
} else {
return mapping.findForward("registfailed");
}
}
}
RegistForm.java
public class RegistForm extends ActionForm {
private String name = null;
private String psw =null;
private String cofirmPsw = null;
public String getCofirmPsw() {
return cofirmPsw;
}
public void setCofirmPsw(String cofirmPsw) {
this.cofirmPsw = cofirmPsw;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPsw() {
return psw;
}
public void setPsw(String psw) {
this.psw = psw;
}
}
#6
问题在六楼代码中间
#7
呵呵,好像没给出问题来哦!
#8
六楼代码中间有问题
//**********************************
//注意这一句,不加在registsuc.jsp就取不到registFormBean,
//为什么???? 但是那个login的例子里就没有这个阿?
request.setAttribute("registFormBean", registForm);
//***************************************
return mapping.findForward("registsuccessed");
//**********************************
//注意这一句,不加在registsuc.jsp就取不到registFormBean,
//为什么???? 但是那个login的例子里就没有这个阿?
request.setAttribute("registFormBean", registForm);
//***************************************
return mapping.findForward("registsuccessed");
#9
Login那个业务的代码是书上的例子
没有任何问题
我仿照那个做了个注册的regist业务
其他的都正常
就是在成功后跳转到的页面取不到前页应该传过来的数据
是一个对象,即RegistForm得实例(Login那个是UserForm)
没有任何问题
我仿照那个做了个注册的regist业务
其他的都正常
就是在成功后跳转到的页面取不到前页应该传过来的数据
是一个对象,即RegistForm得实例(Login那个是UserForm)
#10
RegistForm registForm = (RegistForm) form;
String psw = registForm.getPsw();
String confirmPsw = registForm.getCofirmPsw();
把psw,confirmPsw打出来看看结果~~~看看这两个字符串是什么~~~
System.out.println("psw = "+psw+" confirmPsw = " + confirmPsw);
String psw = registForm.getPsw();
String confirmPsw = registForm.getCofirmPsw();
把psw,confirmPsw打出来看看结果~~~看看这两个字符串是什么~~~
System.out.println("psw = "+psw+" confirmPsw = " + confirmPsw);
#11
在java文件里利用Debug追踪的时候都是正确的
也能跳转到成功页(registsuc.jsp)
但是在registsuc.jsp中 registFormBean == null 这个判断结果是true
也能跳转到成功页(registsuc.jsp)
但是在registsuc.jsp中 registFormBean == null 这个判断结果是true
#12
<action path="/regist" type="users.RegistAction" name="registFormBean" scop="request" input="regist.jsp"/>里的input页是表单验证失败返回的页,当然不能取到值了~~~~
这么些试试
<action path="/regist" type="users.RegistAction" name="registFormBean" scop="request">
<forward id="registsuccessed" path="regist.jsp"/>
</action>
学习框架要搞清楚它的原理和流程~~~
这么些试试
<action path="/regist" type="users.RegistAction" name="registFormBean" scop="request">
<forward id="registsuccessed" path="regist.jsp"/>
</action>
学习框架要搞清楚它的原理和流程~~~
#13
先谢谢一直关注
为什么Login这么些就能取到呢?
<action path="/login" type="users.LoginAction" name="userFormBean" scope="request" input="login.jsp"/>
为什么Login这么些就能取到呢?
<action path="/login" type="users.LoginAction" name="userFormBean" scope="request" input="login.jsp"/>
#14
另外,你上面的那个还是不好用
#15
request.setAttribute("registFormBean", registForm);
你确定这句执行了么?
你确定这句执行了么?
#16
或者你把registsuc.jsp里的
<%
RegistForm registFormBean = (RegistForm)request.getAttribute("registFormBean");
if (registFormBean != null && registFormBean.getName() != null) {
%>
<h1>
Regist successed !<br>
Welcome <%=registFormBean.getName()%> !
<%} else {%>
Regist failed ! Try again !
<%}%>这段换成 ${registFormBean.name}试试
<%
RegistForm registFormBean = (RegistForm)request.getAttribute("registFormBean");
if (registFormBean != null && registFormBean.getName() != null) {
%>
<h1>
Regist successed !<br>
Welcome <%=registFormBean.getName()%> !
<%} else {%>
Regist failed ! Try again !
<%}%>这段换成 ${registFormBean.name}试试
#17
<action path="/regist" type="users.RegistAction" name="registFormBean" scop="request" input="regist.jsp"/>
总算明白你的意思了,你的代码是直接粘贴过来的么??scop写错了,应该是scope,找疯了,细心点啊
总算明白你的意思了,你的代码是直接粘贴过来的么??scop写错了,应该是scope,找疯了,细心点啊
#18
谢谢了
我找了两天了
我都疯了
谢谢了
结贴给分了
我找了两天了
我都疯了
谢谢了
结贴给分了