Java Mailing List Archive

http://www.junlu.com/

Google
Google
Mailing List
Home
Forum Home
JBoss - Java Application Server
Struts - A MVC web framework
Tomcat - JSP/Servlet container
iText - An open source PDF Java Library
JDOM - JDOM XML Parser
J2EE - A mailing list for Java(tm) 2 Platform, Enterprise Edition
J2EE Pattern - An interest list for Sun Java Center J2EE Pattern Catalog
Servlet - A mailing list for discussion about Sun Microsystem's Java Servlet API Technology
JSP - A mailing list about Java Server Pages specification and reference
Struts & Hibernate
Subjects
JSP editor plugin for eclipse ?
org apache jasper JasperException: Unable to compile class for JSP
Tomcat: Connection reset by peer: socket write error
Cannot retrieve definition for form bean null
Struts Tiles Tutorial (free Struts training)
Where do I download Tomcat 4 0 6?
Data Access Object (DAO) pattern, example DAO 's
Where to download Tomcat v 4 1 24 from?
Tomcat 5 0 16 Requested resource not available
Oracle Connection Pooling in 3 2 2
Servlet : Session invalidate
Servlet action is currently unavailable
Tomcat/Struts Unicode Encoding/Decoding problems
Tomcat and webapplication specific java library path
Running a Simple JMS Example
Mapping in workers2 properties
org apache jasper JasperException
Cannot find message resources under key org apache struts action
   MESSAGE
problem with html:text bean throwing exception
Cannot find message resources under key org apache struts action MESSAGE
invalid direct reference problem with solution
Tool for jsp debug Try Sysdeo Eclipse Plugin
Tomcat 5 Cannot load JDBC driver class 'null ' SQL state: null
weblogic ejbc
java properties file
Jboss 3 2 3 Coyote Can 't re
Tomcat 5, Apache2 and mod jk2 integration problem
JBoss example problem new to J2EE
url string for connecting jboss to oracle
Value attribute of <html:checkbox
javax servlet ServletException: BeanUtils populate
HTTP Status 404 The requested resource is not available
5 0 18: Windows XP Pro vs Windows 2000
 
Jsp syntax, style and coding conventions

Jsp syntax, style and coding conventions

2003-10-14       - By Erik Beijnoff

 Back
Reply:     1     2     3     4     5  

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 (See http://ISO-8859.ora-code.com)-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 (See http://ISO-8859.ora-code.com)-1"/>

<jsp:text>
&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
                             "XHTML1-t.dtd" &gt;
</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">
                       @(protected) url(${user.color});
                       @(protected) 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 listserv@(protected) with body: "signoff JSP-INTEREST".
For digest: mailto listserv@(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



©2008 junlu.com - Jax Systems, LLC, U.S.A.