如何在一个jsp中显示两个不同bean的属性

时间:2021-05-05 12:09:19

In a small Struts application (not using any data base) I have a login.jsp and register.jsp. Once the Login is successful it is redirected to success.jsp. Once the Registration is successful it is redirected to the same success.jsp.

在一个小的Struts应用程序(不使用任何数据库)中,我有一个login.jsp和register.jsp。登录成功后,将重定向到success.jsp。注册成功后,它将重定向到相同的success.jsp。

Now, once I login I want to display the login name of the person who logged in and after registration I want to show the name of the person who registered. As I am using the same success.jsp, how will I display them?

现在,一旦我登录,我想显示登录人的登录名,注册后我想显示注册人的姓名。当我使用相同的success.jsp时,我将如何显示它们?

I am using <jsp:usebean>, <jsp:setProperty>, <jsp:getProperty> tags to get the value of the attribute.

我使用 , , 标签来获取属性的值。

2 个解决方案

#1


0  

Check whether bean is initialized, if not so don't use that and use other, for eg for registration only that bean will be init, not login one.

检查bean是否已初始化,如果不是,请不要使用它并使用其他,例如仅注册bean将是init,而不是登录。

#2


0  

I got a solution!

我有一个解决方案!

Alog with Loginform bean and Registerform bean, I took another Bean Suppose UserBean and provided setter and getter methods for the LoginName in that bean and i inherited that bean in my Login and register bean.

使用Loginform bean和Registerform bean,我使用另一个Bean假设UserBean并为该bean中的LoginName提供了setter和getter方法,并且我在Login和register bean中继承了该bean。

In Success jsp I took a form object of UserBean and wrote the following logic

在Success jsp中,我获取了UserBean的表单对象并编写了以下逻辑

UserForm form=null; form=null!=request.getAttribute("LoginForm") ?(UserForm)request.getAttribute(LoginForm) :(UserForm)request.getAttribute("RegisterForm");

UserForm form = null; form = null!= request.getAttribute(“LoginForm”)?(UserForm)request.getAttribute(LoginForm):( UserForm)request.getAttribute(“RegisterForm”);

#1


0  

Check whether bean is initialized, if not so don't use that and use other, for eg for registration only that bean will be init, not login one.

检查bean是否已初始化,如果不是,请不要使用它并使用其他,例如仅注册bean将是init,而不是登录。

#2


0  

I got a solution!

我有一个解决方案!

Alog with Loginform bean and Registerform bean, I took another Bean Suppose UserBean and provided setter and getter methods for the LoginName in that bean and i inherited that bean in my Login and register bean.

使用Loginform bean和Registerform bean,我使用另一个Bean假设UserBean并为该bean中的LoginName提供了setter和getter方法,并且我在Login和register bean中继承了该bean。

In Success jsp I took a form object of UserBean and wrote the following logic

在Success jsp中,我获取了UserBean的表单对象并编写了以下逻辑

UserForm form=null; form=null!=request.getAttribute("LoginForm") ?(UserForm)request.getAttribute(LoginForm) :(UserForm)request.getAttribute("RegisterForm");

UserForm form = null; form = null!= request.getAttribute(“LoginForm”)?(UserForm)request.getAttribute(LoginForm):( UserForm)request.getAttribute(“RegisterForm”);