aspose file tools*
The moose likes Servlets and the fly likes Confusion on 3 Servlets Parts. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Confusion on 3 Servlets Parts." Watch "Confusion on 3 Servlets Parts." New topic
Author

Confusion on 3 Servlets Parts.

Yogendra Joshi
Ranch Hand

Joined: Apr 04, 2006
Posts: 213
Hello ranchers ,

It has been a quite a while i am learning Servlets and Jsp and i am happy that i have rised from Level 0 to Levl 8 out of 10. Thanks for Kathy and Bert for their wonderful book on JSP and Servlets.

While i was reading that book , three questions in my mind and those are the questions which is irritating me. Would appreciate if everyone here who are at their best level please explain answer to my question.

1) if i have 1000 Servlets , do i have to provide servlet and servlet-mapping for all those 1000 Servlets ? There isnt a way out to this ?

2) If web.xml (Deployment Descriptor ) file becomes huge enough , is there a way we can define more then 1 web.xml file i.e divide them. The similar sort of thing i have seen in Struts wherein if struts-config.xml file goes huge , we divide it in 2 parts. Is there a way out for web.xml as well ?

3) For the welcome-file-list , Can i provide something like Test.do which actually would be pointing to some servlet defined up in the servlet element in DD ?

Our expert's opinions would be very much appreciated.

Thanks in Advance.

Yogendra N Joshi.


Meri Zindagi Hain Tab Tak.. Jab Tak Tera Sahara.... Har Taraf Tu Hi Tu Hain SAI Tera Hi Hain Nazara.....
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61230
    
  66

Originally posted by Yogendra Joshi:
1) if i have 1000 Servlets , do i have to provide servlet and servlet-mapping for all those 1000 Servlets ? There isnt a way out to this ?


Explore the Front Controller pattern. It is discussed in this article.

2) If web.xml (Deployment Descriptor ) file becomes huge enough , is there a way we can define more then 1 web.xml file i.e divide them.


No, but there's no need for it to get so big. See answer to #1.
[ July 22, 2007: Message edited by: Bear Bibeault ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Yogendra Joshi
Ranch Hand

Joined: Apr 04, 2006
Posts: 213
Hi bear ,

Thanks for the help on 1st and 2nd question. I went through your article and Front Controller is the exact solution to it.

But what about the 3rd question on welcome file list. Can you put some light on it please ?

Thanks for replying

Yogendra
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Yes, you can also use servlets in the welcome-file-list


[My Blog]
All roads lead to JavaRanch
li bei
Greenhorn

Joined: Jul 22, 2007
Posts: 20
I haven't tried that providing something like Test.do into the welcome-file-list ,so I don't know it work or not.
But , if you want to use Test.do as your welcome-file,you can do like this:
provide a index.html ,set it into the welcome-file , and in the body :

<body>
Loading,please wait...
<script language="javascript">
window.location.href="Test.do";
</script>
</body>

I do it like this.
I hope that would help


I am sorry that my English is poor.If there is something wrong with my words,please tell me .Thank you very much.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61230
    
  66

Originally posted by li bei:
I do it like this.


A JavaScript solution is really inefficient.

For containers that are not up to date (supporting servlets in the welcome list), you'd be far better off using a forward or a redirect.
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
If you web application contains 1000 servlets , then its a big project and
you would definitely not be just using servlets and jsp's for making it.
In future maintaining that would be difficult.

In that case you would be going for some MVC framework , like Struts and struts has a Front Controller.


Rahul Bhattacharjee
LinkedIn - Blog
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

As long as you actually have a file named "index.html" (or whatever you've listed in your welcome-file entry) you can also have a servlet mapping for the same url.

See: WelcomdFileHack in on my site:
http://simple.souther.us
It allows you to use a servlet for a welcome file, even on containers that don't support it.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61230
    
  66

Originally posted by Rahul Bhattacharjee:
In that case you would be going for some MVC framework , like Struts and struts has a Front Controller.


Or just a simple Front Controller. I don't think it's ever necessary to have to take on a monster like Struts.
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
Considering the web application under consideration to be very big ,we can make use of a lot of features that struts provides apart form Front Controller , like validation , slitted struts-file (related to second point of the original post) , etc.

And apart from the 1000 servlets of the application , if any more servlets are required to be added at later point of time then it can be added without much issues and maintaining the application would become much easier.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61230
    
  66

All of those features are just as relevant or irrelevant for small as for large apps. I continue to contend that just because an application gets "big" that it does not need an over-engineered behemoth like Struts to maintain.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Confusion on 3 Servlets Parts.