Since I'm yet working on shaping my conventions and finding any best practises, I'll just give you my thoughts.
First off, I'll be the first to give my full support for the JSP2 way of doing things. I never really liked the "old" way, and for my projects now, I never use it. Any JSP features I use are either EL or custom tags. At times, I also use servlet filters to process the output from my JSP pages (like inserting them into a template and such). I'm not sure if that makes sense. =) So far, I've not been using the XML-syntax, and I'm mostly not concerned with language settings etc, so I felt a bit dizzy at first when reading your code below. ;) From what I can tell, it makes good sense though, even if I tend to prefer to keep the contents of the JSP pages as close to that of the actual output as possible. Signed, Erik Hansson > I'm interested in getting some feedback on what coding conventions and > best practises people are using on this list. > Below I've provided a short page that is a simple example of a login > page for a web application. When you look at examples, tutorials and > discussions on the web, the JSP provided usually doesn't look like this. > As far as I've seen, it's far more common to use the "old" ways of doing > things, such as <%=...%> and often <%if%>...<%else%> statements and so > on. > Granted, JSP 2.0 isn't even final yet, but I like it and code almost > exclusively this way. Those of you who are familiar with this way of > coding, do you find it easier, or do you think it makes the view more > complicated than neccessary? > Those of you who are NOT familiar with JSP 2.0, do you find the syntax > awkward, or do you see a point in doing it the way shown below? > Actually this page doesn't really show the way I code, since I have the > skin part of the rendered html page separated from the content, but I > think the example below is a little bit easier to understand if I show > just one JSP document instead of two. > I'd gladly explain exactly what is happening below, if you are > interested in a deeper understanding of exactly what the page is doing, > but in short: it is a login page with separated message bundles > specified by the users language setting, and integrated validation and > error messaging for the form fields. > Regards Erik Beijnoff > Addsystems > ------------------------------------------------------------------------ > ---------------------- > <?xml version="1.0" encoding="ISO-8859-1"?> > <jsp:root > xmlns:jsp="http://java.sun.com/JSP/Page" > xmlns:c="http://java.sun.com/jstl/core_rt" > xmlns:st="http://com.haywire.stingray.tag" > version="2.0"> > <jsp:directive.page > contentType="text/html" > pageEncoding="ISO-8859-1"/> > <jsp:text> > <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" > "XHTML1-t.dtd" > > </jsp:text> > <c:set value="${requestScope['com.haywire.stingray.state.object']}" > var="state" scope="page"/> > <c:set value="${state.user}" var="user" scope="page"/> > <c:set value="${user.locale}" var="loc" scope="page"/> > <c:set value="${state.msgBundles['page']}" var="msgPage" scope="page"/> > <html > xml:lang="en"> > <head> > <style type="text/css"> > @import url(${user.color}); > @import url(${user.font}); > </style> > <title>${st:msg(msgPage, loc, 'title')}</title> > </head> > <body> > <div style="text-align:center;"> > <div style="font-size:24px;">${st:msg(msgPage, loc, > 'title')}</div> > ${st:actionResult(state, loc)} > <form action="${action['login'].path}" method="post"> > <p>${st:msg(msgPage, loc, 'name')}</p> > <p><input name="username" type="text"/></p> > <p class="error">${st:validateResult(state, loc, > 'username')}</p> > <p>${st:msg(msgPage, loc, 'password')}</p> > <p><input name="password" type="text"/></p> > <p class="error">${st:validateResult(state, loc, > 'password')}</p> > <input type="submit" value="${st:msg(msgPage, loc, 'login')}"/>> > </form> > </div> > </body> > </html> > </jsp:root> > ------------------------------------------------------------------------ > --------------------- > =========================================================================== > To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST". > For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST". > Some relevant archives, FAQs and Forums on JSPs can be found at: > http://java.sun.com/products/jsp > http://archives.java.sun.com/jsp-interest.html > http://forums.java.sun.com > http://www.jspinsider.com =========================================================================== To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST". For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST". Some relevant archives, FAQs and Forums on JSPs can be found at: http://java.sun.com/products/jsp http://archives.java.sun.com/jsp-interest.html http://forums.java.sun.com http://www.jspinsider.com
