question of using Struts for the J2EE pattern

I am now using Struts for the development. I have 3 questions about J2EE

pattern by the use of Struts:

1) How can I use Struts to create the Front Controller? In the book

descibing Front Controller, it is a servlet file which receives the request

and then dispatches to the appropriate view according to the request.

However, in using Struts, should I use the same way? However, I found that

in using Struts, I can call the controller class which subclass

ActionServlet, all the views forwarded are declared in the

struts-config.xml. Am I right in this method?

2) In the project, there is a Front Controller which dispatches the request

to the appropriate view (jsp file). Of course, I use Struts to do this.

However, I expect that the user is impossible for going to the view (jsp

page) directly by typing the address of the jsp file. I hope that the user

can go to the view through the controller only. How can I do this?

3) There is a problem by using browser - when a user browses a site, he can

press the 'back' button to the previous page, and then click the 'forward'

button also. How can I prevent this by using Struts? I found that in some

sites, when the user clicks the 'back' button, an error page displays. How

can I do this? Thanks!

Many Thanks!

Stephen

[1414 byte] By [leefungho] at [2007-9-27 4:42:36]
# 1

Hi!

1-

For your first answer, you're on the right way!

You should define the action in the struts-config.xml. Create entry like :

<actionpath="/nextfile" --> in the url

type="servlet_name"

scope="request"

input="/currentfile.jsp">

<forward name="success"path="/nextfile.jsp"/>

</action>

2-

I don't think

3-

I don't know

Arnaud

arnouf at 2007-7-5 14:30:13 > top of Java-index,Other Topics,Patterns & OO Design...
# 2

I'll take a stab at number 2 and number 3.......

2) You could have the controller object place a "flag" in the request that is dispatched to the JSP. Make the JSP check for that flag to ensure that this request came from the controller object. If the request comes from anywhere other than the controlle object, you can display an error page, or you could redirect them back to the controller. You could also use the HTTPSessionObject to place flags for users and have the JSP check there.

3) Keep a log of the user's activities in the HTTPSession. Whenever a page is invoked, have it check to see if the user has already been here, and if it is appropriate for the user to be here again.

Hope this helps!!

I'm not really a java programmer, I just play one on TV.

colonelForbin at 2007-7-5 14:30:13 > top of Java-index,Other Topics,Patterns & OO Design...
# 3
Hello,Take a look at Struts' Transaction Token pattern.Cheers,Kare
kare at 2007-7-5 14:30:13 > top of Java-index,Other Topics,Patterns & OO Design...