aspose file tools*
The moose likes Servlets and the fly likes Questions of J2EE pattern and Struts Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Questions of J2EE pattern and Struts" Watch "Questions of J2EE pattern and Struts" New topic
Author

Questions of J2EE pattern and Struts

Stephen Lee
Ranch Hand

Joined: Dec 11, 2001
Posts: 74
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
Rick Salsa
Ranch Hand

Joined: Jul 17, 2001
Posts: 173
Originally posted by Stephen Lee:

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?

I don't use struts, but the Front Controller is already created for you. I'm not sure what it is called in struts. All requests are mapped to that servlet in your web.xml file and the Controller servlet will look for the views in your struts xml config file.
Originally posted by Stephen Lee:
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?

Your users will never know what the view pages are named. All the will see is something like:
/ServletController/foo.do
Your users will think that this is the url for the page they are seeing. They have no idea that pages are being included behind the scenes.
Originally posted by Stephen Lee:
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!

There is not way you can control the browser back button using JSP or Servlets. If your worried about Form re-submissions, take a look at the Memento pattern. I believe that's the one. It's covered in Geary's Advanced JavaServerPages.
If you have any other questions, let us know
HTH,
/rick
[ April 27, 2002: Message edited by: rick salsa ]
Stephen Lee
Ranch Hand

Joined: Dec 11, 2001
Posts: 74
For the second questions, I know that the user is impossible to go to the jsp page. However, I ever do not expect to type the link *.do. I just hope that all people enters the site through the main controller only. My main controller is used to forward the request to the other .do site.
Stephen
Simon Brown
sharp shooter, and author
Ranch Hand

Joined: May 10, 2000
Posts: 1913
    
    6
Originally posted by Stephen Lee:
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?

There is a way of doing this - basically you place all of your JSPs underneath the WEB-INF directory of your webapp. Other resources in your webapp can forward to them, but they are not publically available.
I'm going to move this to the Servlets forum...
Simon
Adam Hardy
Ranch Hand

Joined: Oct 09, 2001
Posts: 565
In the struts example application they use a bean that is initialised at the top of each JSPage and it checks whether the user is mean to be there. If they're not, they get forwarded to the login page.
I adopted the same approach myself. Works OK.
I've got a global forward in my struts-config.xml called logon. The bean gets it as a mapping and passes it to the forward method. Should be in the stuff that came with struts. If you can't find it, tell me & I'll post it.

Adam


I have seen things you people would not believe, attack ships on fire off the shoulder of Orion, c-beams sparkling in the dark near the Tennhauser Gate. All these moments will be lost in time, like tears in the rain.
Stephen Lee
Ranch Hand

Joined: Dec 11, 2001
Posts: 74
Thanks! I think I understand the way and I will try it now!
Stephen
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Questions of J2EE pattern and Struts
 
Similar Threads
about struts
Getting org.apache.jasper.JasperException in Struts2
MVC (urgent)
What are the differences btw MVC and Front Controller design patterns?
Difference between servlet and struts