Spring portlet Demo

     

 Spring portlet 的配置过程:

 1、 web.xml  配置

1 < servlet >
2     < servlet-name > view-servlet </ servlet-name >
3     < servlet-class > org.springframework.web.servlet.ViewRendererServlet </ servlet-class >
4     < load-on-startup > 1 </ load-on-startup >
5 </ servlet >
6 < servlet-mapping >
7     < servlet-name > view-servlet </ servlet-name >
8     < url-pattern > /WEB-INF/servlet/view </ url-pattern >
9 </ servlet-mapping >

  

2、*-portlet.xml 的配置

1   < bean  class ="net.ueye.test.DemoController" />
2   < bean  class ="org.springframework.web.servlet.view.InternalResourceViewResolver" >
3       < property  name ="prefix"  value ="/WEB-INF/jsp/" />
4       < property  name ="suffix"  value =".jsp" />
5   </ bean >
6   < context:annotation-config />

 

3、 DemoController

 1 @Controller
 2 @RequestMapping( " view " )
 3 ExpandedBlockStart.gifContractedBlock.gif public   class  DemoController  {
 4    
 5    @RequestMapping
 6ExpandedSubBlockStart.gifContractedSubBlock.gif    public String index(Model model){        
 7        model.addAttribute("accounts",new AccountService().findAll());
 8        return "index";
 9    }

10    
11    @RequestMapping(params="action=edit")
12ExpandedSubBlockStart.gifContractedSubBlock.gif    public String edit(@RequestParam("id")String id,Model model){
13        model.addAttribute("account",new AccountService().get(id));
14        return "edit";
15    }

16    
17    @RequestMapping(params="action=add")
18ExpandedSubBlockStart.gifContractedSubBlock.gif    public String newAccount(){        
19        return "add";
20    }

21    
22    @RequestMapping(params="action=create")
23ExpandedSubBlockStart.gifContractedSubBlock.gif    public void create(ActionResponse response,@ModelAttribute("acc")Account acc,Model model){
24        AccountService as=new AccountService();
25        as.insert(acc);
26        model.addAttribute("accounts",as.findAll());
27        response.setRenderParameter("action","index");
28    }

29    
30    @RequestMapping(params="action=update")
31ExpandedSubBlockStart.gifContractedSubBlock.gif    public void update(ActionRequest request,ActionResponse response,Model model){
32        AccountService as=new AccountService();
33        as.get(request.getParameter("id")).setUsername(request.getParameter("username"));
34        model.addAttribute("accounts",as.findAll());
35        response.setRenderParameter("action","index");
36    }

37    
38    @RequestMapping(params="action=delete")
39ExpandedSubBlockStart.gifContractedSubBlock.gif    public String delete(@RequestParam("id")String id,Model model){
40        AccountService as=new AccountService();
41        as.remove(id);
42        model.addAttribute("accounts",as.findAll());
43        return "index";
44    }

45    
46}

 

4、 index.jsp

 1   < table >
 2      < tr >
 3          < th > ID </ th >
 4          < th > Name </ th >
 5          < th  colspan ="2" > Actions </ th >
 6      </ tr >
 7      < c:forEach  var ="account"  items ="${accounts }" >
 8      < tr >
 9          < td > ${account.id } </ td >
10          < td > ${account.username } </ td >
11          < td >< href ="<portlet:renderURL>
12                     <portlet:param name=" action" value ="edit" />
13                      < portlet:param  name ="id"  value ="${account.id }" />
14                 </ portlet:renderURL > ">Edit </ a >
15          </ td >
16          < td >< href ="<portlet:renderURL>
17                      <portlet:param name=" action" value ="delete" />
18                       < portlet:param  name ="id"  value ="${account.id }" />
19                   </ portlet:renderURL > ">Delete </ a >
20          </ td >
21      </ tr >
22      </ c:forEach >
23      < tr >
24         < td  colspan ="4" >
25             < href ="<portlet:renderURL>
26                        <portlet:param name=" action" value ="add" />
27                         < portlet:param  name ="id"  value ="${account.id }" />
28                      </ portlet:renderURL > ">Add </ a >
29         </ td >
30      </ tr >
31   </ table >

 

5、add.jsp

 1 < form  action ="<portlet:actionURL/>"  method ="post" >
 2     < input  type ="hidden"  name ="action"  value ="create" />
 3     < table >
 4        < tr >
 5          < th > ID </ th >
 6          < td >< input  type ="text"  name ="id"  value ="${account.id }"   /></ td >
 7        </ tr >
 8        < tr >
 9          < th > Name </ th >
10          < th >< input  type ="text"  name ="username" /></ th >
11        </ tr >
12        < tr >
13          < td  colspan ="2" >
14             < input  type ="submit"  value ="submit" />
15             < input  type ="reset"  value ="reset" />
16          </ td >
17         </ tr >
18      </ table >
19 </ form >

      

/Files/rubys/demo.rar

转载于:https://www.cnblogs.com/rubys/archive/2009/04/22/1441671.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值