• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Questions of J2EE pattern and Struts

 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
sharp shooter, and author
Posts: 1913
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Ranch Hand
Posts: 567
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Stephen Lee
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks! I think I understand the way and I will try it now!
Stephen
 
If you are using a rototiller, you are doing it wrong. Even on this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic