This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Servlets and the fly likes Servlets and JSP? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlets and JSP?" Watch "Servlets and JSP?" New topic
Author

Servlets and JSP?

Sam Doder
Ranch Hand

Joined: Feb 06, 2008
Posts: 204
I am working for somebody that wants to convert his servlet classes to
jsp pages. So that he can dynamically make changes to the classes without having to start and stop the server.


Is their any easier way to do it then just to convert all the pages to jsp's.

The main objective is so we don't have to start and stop the server ever time we update a class.

We are using the Jetty server. But we are running these classes on different webservers as well.

Thanks for any help.
[ August 11, 2008: Message edited by: Bear Bibeault ]
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4181
    
  21

In my opinion that is a real bad reason for converting servlets to JSPs. Moving all your servlets to JSPs will make developement harder because the error messages get skewed and hidden.

JSPs should be used for display purposes only. Convert the display part of your Servlets to JSPs. The control part of the servlets should stay in a servlet.

If you want to facilitate testing your code then
1) Use a development-only server until the code is finalized, then pack it and move to the deployment server.
2) See if there is a manager package for Jetty that will allow you to restart individual contexts

I know other servers (like Tomcat) have a manager application that allows you to restart individual contexts. Most servers based on Tomcat (like Glassfish) do as well. I don't know Jetty though.


Steve
K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 2452
    
    8

putting server aside, it is very unlikely to have all jsp pages in large projects. You should probably look into model-view-controller (MVC) design pattern.


K. Tsang JavaRanch SCJP5 SCJD/OCM-JD OCPJP7 OCPWCD5 OCPBCD5
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61315
    
  66

Originally posted by Steve Luke:
In my opinion that is a real bad reason for converting servlets to JSPs.
I'll state it a bit more strongly and say that that is borderline insane! It goes in the exact opposite direction of all notions of best practices and logic. You can tell them I said so.

In order to accomplish this, you'd have to have all Java code in the JSPs. No classes, no beans, no tags, no tag files. What a complete and utter mess it would be!

Insane!
[ August 11, 2008: Message edited by: Bear Bibeault ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Sam Doder
Ranch Hand

Joined: Feb 06, 2008
Posts: 204
I thought it wasn't a good idea but I cann't argue with the boss to much so.


In order to accomplish this, you'd have to have all Java code in the JSPs. No classes, no beans, no tags, no tag files. What a complete and utter mess it would be!

What I think he wants is to code all the servlets into jsp pages.
And if a servlet extended another class convert it into a jsp include statment. I know this will not work very well.

Does anybody know how to beable to get the updating of a file without shuting down the server?

I know with jsp you can set the time for it to recompile updated jsp files.
But when I make a change to a servlet file I want it, to act exactly like a jsp. In that when I modify a servlet I don't have to shutdown and restart the server before the changes take place.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61315
    
  66

Originally posted by Sam Doder:
I thought it wasn't a good idea but I cann't argue with the boss to much so.
I think it's perfectly reasonable, in fact an important part of an engineer's job, to bring up objections to bad ideas. All in a professional way of course.

And if a servlet extended another class convert it into a jsp include statment. I know this will not work very well.
It won't work at all. Including isn't anywhere the same thing as extending. You'd need to flatten any extending into a single class.

Does anybody know how to beable to get the updating of a file without shuting down the server?
You rarely need to shut down the server. Most app servers will allow you to simply restart an affected web application. Does your boss know anything about web applications?

I know with jsp you can set the time for it to recompile updated jsp files.
Not really. The JSP engine detects when the JSP has changed and re-translates it. It then uses a custom class-loader to reload it on-the-fly.

But when I make a change to a servlet file I want it, to act exactly like a jsp. In that when I modify a servlet I don't have to shutdown and restart the server before the changes take place.
As I said, you don't need to shut down the server. Simply restart the web app. But there's no getting around the web app restart.
[ August 11, 2008: Message edited by: Bear Bibeault ]
Sam Doder
Ranch Hand

Joined: Feb 06, 2008
Posts: 204
As I said, you don't need to shut down the server. Simply restart the web app. But there's no getting around the web app restart.


When I said shutdown the server I meant shutdown the application server.
NOT PHYSICAL SHUT DOWN THE MACHINE!
Because I don't want to shutdown the whole entire application server either, because I have more then one application running on the application server.

So is their away to only shutdown/restart a piece of the application server.

Because if I can get the jetty server to only restart a certain application when it is updated then I may beable convince him of not doing it this way.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

Originally posted by Sam Doder:
Because I don't want to shutdown the whole entire application server either, because I have more then one application running on the application server.

So is their away to only shutdown/restart a piece of the application server.
Seems to me that Bear suggested doing exactly that.

I spent a few minutes googling and found the Jetty documentation page. It had a link labelled "Hot Deploy" -- which is precisely what you are asking about. And I see that you can get commercial support for Jetty. You (or your boss, I guess) should consider signing up for that. It might save a lot of fumbling around in the dark.
Sam Doder
Ranch Hand

Joined: Feb 06, 2008
Posts: 204
Thanks for that.
However we have web application servers other then jetty.

So I need a general way to support this.
Pat Farrell
Rancher

Joined: Aug 11, 2007
Posts: 4659
    
    5

Sam, Listen to the advise upthread. This is a really dumb idea, its contrary to the whole "separate business logic from presentation" mantra that has been the goal of developers for the past decade.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61315
    
  66

Yes, I never meant shut down the machine. Any app server worth its salt will allow you to stop and restart individual applications.

Send your boss here. We'll set him straight.
Sam Doder
Ranch Hand

Joined: Feb 06, 2008
Posts: 204
Thanks guys for your help.
I will bring this up and let him.
 
jQuery in Action, 2nd edition
 
subject: Servlets and JSP?