KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > velocity > demo > action > PostCommand


1 package org.apache.velocity.demo.action;
2
3 /*
4  * Copyright 1999,2004 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18
19 // Java
20
import java.util.*;
21
22 // Java Servlet
23
import javax.servlet.http.HttpServlet JavaDoc;
24 import javax.servlet.http.HttpServletRequest JavaDoc;
25 import javax.servlet.http.HttpServletResponse JavaDoc;
26
27 // Velocity
28
import org.apache.velocity.context.Context;
29
30 // Demo
31
import org.apache.velocity.demo.om.*;
32
33 /**
34  * Handles posting new messages to the Forum
35  *
36  * @author <a HREF="mailto:daveb@miceda-data.com">Dave Bryson</a>
37  * @version $Revision: 1.2.14.1 $
38  * $Id: PostCommand.java,v 1.2.14.1 2004/03/04 00:18:29 geirm Exp $
39  */

40 public class PostCommand extends Command
41 {
42     public PostCommand( HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc resp )
43     {
44         super( req, resp );
45     }
46
47     /**
48      * Collects the parameters from the Form.
49      * Creates a new message and stores it then
50      * gets a fresh list and calls the list template
51      */

52     public String JavaDoc exec( Context ctx )
53     {
54         String JavaDoc name = request.getParameter("name");
55         String JavaDoc subject = request.getParameter("subject");
56         String JavaDoc email = request.getParameter("email");
57         String JavaDoc content = request.getParameter("content");
58         
59         Message message = new Message();
60         message.setName( name );
61         message.setSubject( subject );
62         message.setEmail( email );
63         message.setContents( content );
64         
65         ForumDatabase.postMessage( message );
66         
67         Object JavaDoc[] list = ForumDatabase.listAll();
68         
69         ctx.put("listall", list );
70         ctx.put("hasMessages", Boolean.TRUE );
71         
72         return ListCommand.LIST;
73     }
74 }
75
76
Popular Tags