• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

to visualize servlet codes generated from JSPs

 
Guennadiy VANIN
Ranch Hand
Posts: 898
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
green's question:
From JBuilder tutorial:
JSPs have some advantages and some disadvantages compared to servlets. Some of the advantages are: - Easy to incorporate existing JavaBeans. Some of the disadvantages of JSPs are: Invisible generated servlet code can be confusing, as previously mentioned.

Why it is uneasy to incorporate Javabeans in servlets?
Why it is impossible to visualize servlet codes generated from JSPs? or it is?
 
chanoch wiggers
Author
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by G Vanin:
green's question:

Why it is uneasy to incorporate Javabeans in servlets?
Why it is impossible to visualize servlet codes generated from JSPs? or it is?

its not uneasy to use java beans from servlets. JSP servlet code is not intended to be used by developers so its not particularly readable - you cant maintain it unless you get a hold of a compiler that deliberatetly creates readable servlet code in case you want to deploy maintainable compiled jsps rather than raw text. here is an example of some old jsps I have lying around - remember the bits you have to maintain are not the nicely formatted stuff, even if its not particularly easy to understand its the HTML:
// HTML // begin [file="/addArticle.jsp";from=(0,0);to=(96,111)]
out.write("<html><!-- #BeginTemplate \"/Templates/home_news.dwt\" -->\r\n<head>\r\n<!-- #BeginEditable \"doctitle\" --> \r\n<title>Page title</title>\r\n<!-- #EndEditable --> \r\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">\r\n<style type=\"text/css\">\r\n<!--\r\n.menu { color: #e3e7e8}\r\n-->\r\n</style>\r\n<meta name=\"keywords\" content=\"blah, blah blah\"/>\r\n</head>\r\n\r\n<body bgcolor=\"#FFFFFF\">\r\n<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"750\" height=\"150\">\r\n <tr> \r\n <td width=\"157\" valign=\"top\" height=\"148\"><img src=\"images/
etc etc
example code
============
public void _jspService(HttpServletRequest request, HttpServletResponse response)
throws java.io.IOException, ServletException {
JspFactory _jspxFactory = null;
PageContext pageContext = null;
HttpSession session = null;
ServletContext application = null;
ServletConfig config = null;
JspWriter out = null;
Object page = this;
String _value = null;
try {
if (_jspx_inited == false) {
synchronized (this) {
if (_jspx_inited == false) {
_jspx_init();
_jspx_inited = true;
}
}
}
_jspxFactory = JspFactory.getDefaultFactory();
response.setContentType("text/html;ISO-8859-1");
pageContext = _jspxFactory.getPageContext(this, request, response,
"", true, 8192, true);
application = pageContext.getServletContext();
config = pageContext.getServletConfig();
session = pageContext.getSession();
out = pageContext.getOut();
// HTML // begin [file="/addArticle.jsp";from=(0,0);to=(96,111)]
out.write("<html><!-- #BeginTemplate \"/Templates/home_news.dwt\" -->\r\n<head>\r\n<!-- #BeginEditable \"doctitle\" --> \r\n<title>Page title</title>\r\n<!-- #EndEditable --> \r\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">\r\n<style type=\"text/css\">\r\n<!--\r\n.menu { color: #e3e7e8}\r\n-->\r\n</style>\r\n<meta name=\"keywords\" content=\"blah, blah blah\"/>\r\n</head>\r\n\r\n<body bgcolor=\"#FFFFFF\">\r\n<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"750\" height=\"150\">\r\n <tr> \r\n <td width=\"157\" valign=\"top\" height=\"148\"><img src=\"images/
etc etc
// end
// HTML
// begin [file="/addArticle_form.jsp";from=(41,2);to=(47,6)]

if(session.getAttribute("user") == null) {
String username = (String)request.getParameter("j_username");
String password = (String)request.getParameter("j_password");

if(username == null || username.equals("") || password == null || password.equals("")) {

// end
// HTML // begin [file="/addArticle_form.jsp";from=(47,8);to=(49,73)]
out.write("\r\n\r\nYou must log in. <a href=\"login.jsp?referredBy=addArticle.jsp\">Log in</a>");
// end
// begin [file="/addArticle_form.jsp";from=(49,75);to=(52,6)]
 
Guennadiy VANIN
Ranch Hand
Posts: 898
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Chanoch,
thanks
 
Bernd Stransky
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
1. Easy to incorporate existing JavaBeans
I assume they mean that someone who is not familiar with Java (like a Web designer) can use JavaBeans without knowing too much about Java with the standard built in action elements jsp:useBean, jsp:setProperty and jsp:getProperty.
2. Invisible generated servlet code can be confusing
If you run into translation, compile or runtime errors, it might be difficult to debug your JSP code, because error messages you get refer to the generated servlet code. You have to look at the generated code as well to find out what is wrong, i.e. you need to understand Java.
Hope this helps,
Bernd
SCJP
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic