随笔 - 71  文章 - 15  trackbacks - 0
<2024年5月>
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678

因为口渴,上帝创造了水;
因为黑暗,上帝创造了火;
因为我需要朋友,所以上帝让你来到我身边
Click for Shaanxi xi'an, Shaanxi Forecast
╱◥█◣
  |田|田|
╬╬╬╬╬╬╬╬╬╬╬
If only I have such a house!
〖总在爬山 所以艰辛〗
Email:myesjoy@yahoo.com.cn
NickName:yesjoy
MSN:myesjoy@hotmail.com
QQ:150230516

〖总在寻梦 所以苦痛〗

常用链接

留言簿(3)

随笔分类

随笔档案

文章分类

文章档案

Hibernate在线

Java友情

Java认证

linux经典

OA系统

Spring在线

Structs在线

专家专栏

企业信息化

大型设备共享系统

工作流

工作流产品

网上购书

搜索

  •  

最新评论

阅读排行榜

评论排行榜

Jodd 是一个开源项目, http://jodd.sourceforge.net 有一个好用的 jsp 标签,可以大大简化有表单输入的 controller

 

使用 Jodd 的优点:

<!--[if !supportLists]-->1.<!--[endif]-->简化和统一controller,抛弃extends SimpleFormController,统一使用implements Controller的方式。

<!--[if !supportLists]-->2.<!--[endif]-->简化JSP页面的bind,不需要一个字段一个字段的绑定。

<!--[if !supportLists]-->3.<!--[endif]-->bean没有任何要求,可以使用任意的bean做为formBean.

 

使用方法简介:

<!--[if !supportLists]-->1.<!--[endif]-->jodd.jar放到web-inf->lib下,在web.xml里声名标签:

< taglib >

       
< taglib-uri > jodd </ taglib-uri >

       
< taglib-location > /WEB-INF/lib/jodd.jar </ taglib-location >

    
</ taglib >

 

<!--[if !supportLists]-->2.<!--[endif]-->任意的一个javaBean做为FormBean

package  caike; 

public   class  User {

       
private  String userName; 

       
private  String password;
     

       
public  String getPassword() {

              
return  password;

       } 

       
public   void  setPassword(String pwd) {

              
this .password  =  pwd;

       } 

       
public  String getUserName() {

              
return  userName;

       } 

       
public   void  setUserName(String username) {

              
this .userName  =  username;

       }
 

}

<!--[if !supportLists]-->3.<!--[endif]-->JSP页面使用jodd tag:,比如对应用户登录页面的

<% @page import = " caike.User " %>

<% @taglib uri = " jodd "  prefix = " jodd " %>

 

< jodd:form  beans ="user"  scopes ="session" >

< form  action ="my.htm"  method ="post"   >
 

    
< table  width ="300"  border ="0"  cellspacing ="0"  cellpadding ="0"

       align
="center"  class ="white" >  

       
< tr >

           
< td  height ="32"  align ="right"  width ="107" > 用户名: </ td >

       
< td  height ="32"  width ="193" >< input  type ="text"  name ="userName"

              class
="input"  size ="20" >   </ td >           

       
</ tr >

       
< tr >

           
< td  height ="33"  align ="right"  width ="107" > 密码: </ td >

           
< td  height ="33"  width ="193" >< input  type ="password"  name ="password"

              class
="input"  size ="21" ></ td >

       
</ tr >
      

        
< tr >

           
< td  height ="69"  align ="center"  colspan ="2" >

            
< input  type ="submit"  name ="Submit"  value ="登录" >

       
</ tr >

    
</ table >

</ form >

</ jodd:form >

 

<!--[if !supportLists]-->4.<!--[endif]-->Dispatch-servelt.xml中对controller的配置

<bean id="myController" class="caike.MyController">    

    </bean>

    不再需要这种方式:

    <!--

       <bean id="myController" class="caike.MyFormController">    

       <property name="commandClass" value="caike" />      

       <property name="formView" value="userForm" />   

       </bean>

    -->

<!--[if !supportLists]-->5.<!--[endif]-->controller中取出user

package  caike; 

import  javax.servlet.http.HttpServletRequest;

import  javax.servlet.http.HttpServletResponse; 

import  jodd.bean.BeanUtil; 

import  org.springframework.web.servlet.ModelAndView;

import  org.springframework.web.servlet.mvc.Controller;

 

public   class  MyController  implements  Controller {

 

       
public  ModelAndView handleRequest(HttpServletRequest request,

                     HttpServletResponse response) 
throws  Exception {

 

              User user 
=   new  User();

              BeanUtil.load(user, request);

              System.out.println(
" 用户名: "   +  user.getUserName()  +   "  密码: "   +  user.getPassword());

              
return   null ;

       }

 

}

 

需要注意的地方:

表单中对应的名字 name javaBean 里对应的属性名要相同。

<input type="text" name="userName"

              class="input" size="20">

public class User {

       private String userName;

.......

 参考:

http://www.blogjava.net/calvin/archive/2005/08/24/10914.html

  花钱的年华    简化Spring(4)--View层

posted on 2006-11-10 15:20 ★yesjoy★ 阅读(1365) 评论(0)  编辑  收藏 所属分类: Spring学习

只有注册用户登录后才能发表评论。


网站导航: