I would take some time and do a little research
on the MVC architecture and web applications.

You want to avoid business logic in your view (.jsp) and leverage
other J2EE components for authentication and authorization.

So, for the example below, you may want to investigate the
the use of container managed authorization/authentication or
the use of a Filter (SecurityFilter).

The general idea is to protect resources using either technique
and redirect to the appropriate resource if the user passes the login.
Else, redirect to the approprate page.

For the example below, you would want to protect all pages in the banking
application unless the user has been authenticated and is authorized to view
the page. You could use one of the above approaches to do that.

Next, once the user has been authenticated and is authorized to view the page,
you could define a Struts action which would be invoked prior to viewing the 
page;
ShowUserAccountList. This action would delegate to the appropriate business 
logic
which would retrieve the necessary user information and place it in a JavaBean
which you could place in request scope. ShowUserAccountList would then look up
a forward mapping which would allow the controller to forward to the 
appropriate .jsp page, where you could use either JSTL or
Struts custom tags
to iterate over the user account list and render the appropriate information.


There are plenty of examples and advice for this type of architecture.
You can start here:
http://struts.apache.org/userGuide/index.html


robert

> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
> Sent: Sunday, November 07, 2004 1:00 PM
> To: [EMAIL PROTECTED]
> Subject: What is a good Struts application?
>
>
> hi,
>
> I am a newbie to Apache Struts. I'd like to know what a good Struts 
> application looks like.
> In our JSP pages, should we try to avoid embedded java code but use tags?
> For example, i have an index.jsp page for my banking application.
> When a user comes to this page, it displays the login form. When a user has 
> already logged
> in, it displays the user's account list. The user information is saved in the 
> session as
> an instance of my User class. I wrote my index.jsp as the following:
>
>
>
> <%
> User user = (User)session.getAttribute("USER");
> if (user==null) {
>   %>
>   <html:form action="Login">
>     Login Name: <html:text property="loginName" size="16"/><br/>
>     Password  : <html:password property="password" size="16"/><br/>
>   </html:form>
>   <%
> } else {
>   Iterator iter = Account.getAccountList(user);
>   int count = 0;
>   while (iter.hasNext()) {
>     count ++;
>     Account account = (Account)iter.next();
>     %>
>     <%= account.getName() %>
>     (created on <%= account.getCreatedDate() %>)<br/>
>     <%
>   }
>   %>
>   Total <%= count %> accounts found.<br/>
>   <%
> }
> %>
>
>
>
> Here are my questions:
>
> 1. My business object is the Account class. It provides
> a static method getAccountList(User user) to get an iterator
> of all the accounts of the given user. I am calling this method directly
> in my index.jsp file, but it does not seem to be a good struts programming
> style. So what is the preferred way for doing this?
>
> 2. I used embedded java code for checking whether a user has logged in.
> Should i use tags in the bean taglib or logic taglib to get an object from
> the session and check it?
>
> Thanks for any reply.
>
> heavy ZHENG
>
>
>
> ZHENG Zhong
>
>
> ---------------------------------
> Do You Yahoo!?
> 150万曲MP3疯狂搜,带您闯入音乐殿堂
> 美女明星应有尽有,搜遍美图、艳图和酷图
> 1G就是1000兆,雅虎电邮自助扩容!


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to