aspose file tools*
The moose likes JSP and the fly likes should all the pages of a web-app be in jsps or servlets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "should all the pages of a web-app be in jsps or servlets" Watch "should all the pages of a web-app be in jsps or servlets" New topic
Author

should all the pages of a web-app be in jsps or servlets

nagarjuna borra
Ranch Hand

Joined: Jan 14, 2012
Posts: 41
Should all the pages in a web app be in jsps or servlets or php or whatever else???

what goes wrong when i use static html pages when i dont need any dynamic presentation like in simple forms???

for an example:consider a home page of website is a simple login,a simple static html page can do that..why use any jsp page or servlet for that...

im worried abt that because most of my friends are doing same i.e writing every page in jsp.and when i asked them they replied that it should be done in that way.

are they wright...if so why???

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60997
    
  65

If the page is truly static there should be no problem just having it an HTML page. But, and this is a big but, if the page has any links or references to external resources such as images, stylesheets or script file in it (and how many pages would not?), it should use server-relative addressing for the link and resource URLs. And that can only be done in a JSP as the context path needs to be dynamically determined with the following EL expression: ${pageContext.request.contextPath}

Note that at no time after 2002 should a JSP page contain any Java code or scriptlets.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
nagarjuna borra
Ranch Hand

Joined: Jan 14, 2012
Posts: 41
Bear Bibeault wrote:If the page is truly static there should be no problem just having it an HTML page. But, and this is a big but, if the page has any links or references to external resources such as images, stylesheets or script file in it (and how many pages would not?), it should use server-relative addressing for the link and resource URLs. And that can only be done in a JSP as the context path needs to be dynamically determined with the following EL expression: ${pageContext.request.contextPath}

.


Thanks...finally a relief!!

Bear Bibeault wrote:Note that at no time after 2002 should a JSP page contain any Java code or scriptlets.


im aware of that...not the year though..

but,if seperation of control and presentation is not a big problem(i.e simple web-apps) can i still continue the pracice of writing java code/scriptlets in jsp pages???

what i mean is would there be any other problems??
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60997
    
  65

There is no need whatsoever to put Java code in a JSP. Ever.

Anything that should be done in a JSP can be done with one of the existing JSP 2 mechanisms. If it can't, it's a big red flag that you are trying to do something in a JSP that should not be done in a JSP.

If your web app is properly structured, it's easy to do things that need to be done outside of the JSP in the page controller.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

nagarjuna borra wrote:but,if seperation of control and presentation is not a big problem(i.e simple web-apps) can i still continue the pracice of writing java code/scriptlets in jsp pages???

what i mean is would there be any other problems??


Well, yes, there would be a problem. One day you would come in to work and realize that your "simple web-app" is now a complicated and unmaintainable beast. That's the natural progression of software -- people can't just leave it alone, they keep having to add to it. So over time "untidy" turns into "messy" and then into "a steaming pile". And you'll always find that implementing new features takes precedence over cleaning up messiness.

So don't start with "untidy" and hopefully you won't end up with that steaming pile.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60997
    
  65

nagarjuna borra wrote:but,if seperation of control and presentation is not a big problem(i.e simple web-apps)

Paul said it very well, but just to re-emphasize: not properly separating presentation and control is always a big problem; even in "simple web apps".

Develop good coding habits and use them always.
nagarjuna borra
Ranch Hand

Joined: Jan 14, 2012
Posts: 41
Bear Bibeault wrote:There is no need whatsoever to put Java code in a JSP. Ever.

Anything that should be done in a JSP can be done with one of the existing JSP 2 mechanisms. If it can't, it's a big red flag that you are trying to do something in a JSP that should not be done in a JSP.

If your web app is properly structured, it's easy to do things that need to be done outside of the JSP in the page controller.


i didnt get that...JSP 2 mechanisms???,never even heard of it.

I did google it but couldnt get appropriate results

im a newbie.im just digging basics first.

anyways..if i want to retrieve data from database and present it to user...how would you do it(no offense meant,just want to know it)
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60997
    
  65

JSP 2 introduced the EL and JSTL, simple custom tags, tag files, and so on.

JSP 1 style scriptlets, scriptlet expressions, and declarations should not be used in any JSP page created after the introduction of JSP 2 in 2002. That's 10 years ago. That also includes old mechanisms like<jsp:getProperty> and <jsp:setProperty> that have better JSTL equivalents.
nagarjuna borra
Ranch Hand

Joined: Jan 14, 2012
Posts: 41
ok,now i have some clarity.

Thanks to you people.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41509
    
  53
There are other ways of creating an HTML view than JSP, though - libraries like FreeMarker and Apache Velocity can also be used.


Ping & DNS - my free Android networking tools app
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60997
    
  65

True. Or Play! or any other number of templating frameworks. They're just a blip with hardly any penetration though.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: should all the pages of a web-app be in jsps or servlets