• Post Reply Bookmark Topic Watch Topic
  • New Topic

murach's servlets & JSP's  RSS feed

 
jaideep amuloju
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Author . I have seen a few applications where the MVC and java specification is not followed properly, thus resulting into more complex to maintain. Does this book instruct the reader what not to be used. For example , it is not recommended to write java code in JSP's . But sometimes I feel it is difficult to write jsp file just by using JSTL and restricting java code. And do you think using instance variables in servlets is fine ??

Thank you,
Jaideep
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

But sometimes I feel it is difficult to write jsp file just by using JSTL and restricting java code.

What situations are those? If the EL/JSTL becomes too complex, you always have the option of creating your own tags, either via tag files, or by writing tag classes.

And do you think using instance variables in servlets is fine ?

It's OK only if they're used in a thread-safe manner. That means they can't change after initialization, or you need to guard access to them via synchronization, ThreadLocal, or some other appropriate means.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66158
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The whole point of the JSTL and EL is to simplify JSP pages. If you find it is making them more complex, you may not be setting things up correctly. Your page controller should be doing all the heavy lifting so that the JSP page itself can be as simple as possible. Is it possible that you are not leveraging the power of the controller to make things easier for the JSP?

Also, in well over a decade of using Servlet technology, I have never felt a need to use a read/write instance variable in a servlet. There's always somewhere more appropriate to be storing data.
 
Joel Murach
Author
Ranch Foreman
Posts: 127
12
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jaideep,

I agree with the points that Bear and Ulf have made, and it seems to me that our book follows their advice. In our book, a servlet controller always sets up the variables so that the JSP view can be as simple as possible using only EL or JSTL, never Java code. We present show how to include Java in one JSP, but only as an example of what NOT to do. Similarly, none of the servlets in our book use instance variables, except one that we present as an example of what NOT to do.

Thanks!

Joel
 
jaideep amuloju
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks to Ulf,Bear & Joel for the reply.
We have developed a small project where we haven't bothered to follow java rules, as it is a smaller project it dint matter much. I am comfortable in writing java code rather than using tags in jsp because I am not much aware of using tags and I guess we haven't make use of the controller properly.We have written data access logic(jdbc) also in the JSP sometimes.
When we use frameworks they release few more tag libraries ,so I feel its confusing what tag should be used,either the JSTL/EL or the tags given by framework . I am not well experienced to create tags by writing tag classes. I would like to make use of the MVC more effectively and need to learn the JSTL/EL so that I can make the jsp simple.
Its great that the book covers the examples and explanation that I need. Thank you.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!