当前位置: 代码迷 >> Java Web开发 >> freemarker有关问题,
  详细解决方案

freemarker有关问题,

热度:116   发布时间:2016-04-17 13:42:36.0
freemarker问题,请指教!
我有这样一个模板文件(用于添加内容的):
<#import   "/lib/common.ftl "   as   com>


<@com.page   title= "Entry   added ">
    <p> You   have   added   the   following   entry   to   the   guestbook:
    <p> <b> Namess: </b>   ${entry.namess}

    <#if   entry.email?length   !=   0>
        <p> <b> Email: </b>   ${entry.email}
    </#if>
    <p> <b> Message: </b>   ${entry.message}
    <p> <a   href= "index.a "> Back   to   the   index   page... </a>
</@com.page>
它对应的实体对象为:
public   class   GuestbookEntry   {
        private   String   namess;
        private   String   email;
        private   String   message;
       
        public   GuestbookEntry(String   name,   String   email,   String   message)   {
                this.namess   =   name;
                this.email   =   email;
                this.message   =   message;
        }

        public   String   getEmail()   {
                return   email;
        }

        public   String   getMessage()   {
                return   message;
        }

        public   String   getName()   {
                return   namess;
        }

}
处理的SERVLET中的代码为:
public   void   addAction(HttpServletRequest   req,   Page   p)   throws   IOException,
ServletException
{
List   errors   =   new   ArrayList();
String   name   =   req.getParameter( "name ");
String   email   =   req.getParameter( "email ");
String   message   =   req.getParameter( "message ");
if   (isBlank(name))
{
errors.add( "You   must   give   your   name. ");
}
if   (isBlank(message))
{
errors.add( "You   must   give   a   message. ");
}

//   Was   the   sent   data   was   correct?
if   (errors.isEmpty())
{
if   (email   ==   null)
email   =   " ";
//   Create   and   insert   the   new   guestbook   entry.
GuestbookEntry   e   =   new   GuestbookEntry(name.trim(),   email.trim(),
message);
synchronized   (guestbook)
{
guestbook.add(0,   e);
}
//   Show   "Entry   added "   page.
p.put( "entry ",   e);
p.setTemplate( "add.ftl ");
}
else
{