• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

can i write java code in jsp

 
Ranch Hand
Posts: 689
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hey everybody suggested me to not to write java code in jsp using scriptlets
but here i am doing one simple webapplication which displays 5 records out of 100 records when ever user press on next button.
so fo this i am writing the java code in jsp.for better performance..
if i use this java code in servlet i can eliminate java code inside jsp file.but accoring to performance i think it is not so good because if the use clicks on next button the control goes to servlets and gets the first 5 records and so on...
which is the better way ??
any experienced developer can give be the best suggestion..
thanks in advance

cinux
 
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It seems that your applicaiton is really a small one. So please dont hesitate to write code on jsp.

Many people may tell that, it's real sin , if you write code on jsp's rather you must use any latest framework.
Dont mind them.

Coming to performance, if your problem will solve with a little code on jsp's, then do it. Otherwise you will waste time in giving control to servlet and back.


 
saikrishna cinux
Ranch Hand
Posts: 689
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
but i think jsp also becomes a servlet when we send a request to the jsp file.
what is the difference if we wirte the java code in a servlet instead of writing everything in jsp file???
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Personally, I always structure my applications properly regardless of their size. All too often what starts as a "small project" snowballs into something bigger, and if you've started off with a poor structure it's unlikely to scale well. It's also just good discipline and practice, and a good habit to get into.

Performance is not a factor. It will have no discerable performance impact to factor processing code into a servlet which dispatches to a JSP over just plunking the code down into the page.

It is also incorrect to think that in order to write scriptless JSP pages that you have to use "any latest framework". You don't. I don't.

And finally, the advice of anyone who says "dont listen to other people's advice" is the first that I would regard with caution.
 
Ranch Hand
Posts: 1090
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yeah actually as bear mentioned. Please use the standard practices. They are standards because they have been tested through ages.

Secondly it won't effect the performance as you think. Don't measure performance like if it's in the same JSP it would execute faster becasue

1. The JSPs in any case would be translated to servlets.
2. You would not be able to reuse the code / or would be difficult to reuse a code written in JSP.
3. Debugging and maintaining code in a JSP is very .
4. Moreover in case you get into this habbit and you code like this it would be dificult to chnage jobs and probably hold on to the job present even.
 
saikrishna cinux
Ranch Hand
Posts: 689
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Bear Bibeault:
Personally, I always structure my applications properly regardless of their size. All too often what starts as a "small project" snowballs into something bigger, and if you've started off with a poor structure it's unlikely to scale well. It's also just good discipline and practice, and a good habit to get into.

Performance is not a factor. It will have no discerable performance impact to factor processing code into a servlet which dispatches to a JSP over just plunking the code down into the page.

It is also incorrect to think that in order to write scriptless JSP pages that you have to use "any latest framework". You don't. I don't.

And finally, the advice of anyone who says "dont listen to other people's advice" is the first that I would regard with caution.



i dont know any of the frameworks available in the market now..
the only way is i have to follow MVC2 architecture that is jsp,servlet ,bean..
so for this ishoudl definitely use... java code in my jsp files.....
so what is ur suggestion now
waiting for ur reply.
cinux
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

the only way is i have to follow MVC2 architecture that is jsp,servlet ,bean.. so for this ishoudl definitely use... java code in my jsp files.....


You don't need to use Java scriptlets in JSP pages, no matter whether you use MVC1, or MVC2, or neither of them. Check out JSTL and the expression language (EL).
 
Ranch Hand
Posts: 1026
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can someone explain MVC1 and MVC2. where does struts figure in?
 
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Some articles:
http://www.javaworld.com/javaworld/jw-12-1999/jw-12-ssj-jspmvc.html

http://java.sun.com/blueprints/guidelines/designing_enterprise_applications_2e/web-tier/web-tier5.html

Struts is a framework that employs the MVC/model2 architecture. Basically it helps you follow some decent design principles with your web application.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Read this article.
 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by saikrishna cinux:
hey everybody suggested me to not to write java code in jsp using scriptlets
but here i am doing one simple webapplication which displays 5 records out of 100 records when ever user press on next button.
so fo this i am writing the java code in jsp.for better performance..
if i use this java code in servlet i can eliminate java code inside jsp file.but accoring to performance i think it is not so good because if the use clicks on next button the control goes to servlets and gets the first 5 records and so on...
which is the better way ??
any experienced developer can give be the best suggestion..
thanks in advance

cinux




There is a tag library out there which does the pagination. and its free.

the Taglib is displayTag. Try it.. you donnt even have to give control back to your Servlet.
 
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by saikrishna cinux:
hey everybody suggested me to not to write java code in jsp using scriptlets
but here i am doing one simple webapplication which displays 5 records out of 100 records when ever user press on next button.
so fo this i am writing the java code in jsp.for better performance..
if i use this java code in servlet i can eliminate java code inside jsp file.but accoring to performance i think it is not so good because if the use clicks on next button the control goes to servlets and gets the first 5 records and so on...
which is the better way ??
any experienced developer can give be the best suggestion..



No performance issues here. Its just about the readablity, easeness, and the use of right technology.

Recommendations:

- No Java in JSP
- No DB operation stuff in JSP

For pagination you can search the same forum or Servlet forum with the word pagination and you would get lot of threads discussing that.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic