Source Code Cross Referenced for Controller.java in  » Code-Analyzer » JBlanket » csdl » stackmvc » control » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Code Analyzer » JBlanket » csdl.stackmvc.control 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


01:        package csdl.stackmvc.control;
02:
03:        import java.io.IOException;
04:
05:        import javax.servlet.RequestDispatcher;
06:        import javax.servlet.ServletConfig;
07:        import javax.servlet.ServletException;
08:        import javax.servlet.http.HttpServlet;
09:        import javax.servlet.http.HttpServletRequest;
10:        import javax.servlet.http.HttpServletResponse;
11:
12:        import csdl.stackmvc.control.command.Command;
13:
14:        /**
15:         * The central servlet that serves as the controller in the MVC pattern
16:         * for JSP page dispatching.
17:         *
18:         * @author Philip M. Johnson
19:         * @author Jitender Miglani (did minor changes)
20:         */
21:        public class Controller extends HttpServlet {
22:
23:            private String exceptionAttribute = "javax.servlet.jsp.jspException";
24:            private String commandParameter = "CommandName";
25:
26:            /**
27:             * The init method that must be overridden in subclasses so that super.init is called.
28:             *
29:             * @param conf The servlet configuration information.
30:             * @exception ServletException If errors occur during initialization.
31:             */
32:            public void init(ServletConfig conf) throws ServletException {
33:                super .init(conf);
34:            }
35:
36:            /**
37:             * Receives all user requests and dispatches to appropriate command class
38:             * for processing. The command class is determined by the value of the "CommandName"
39:             * parameter in the request; if none is supplied, then "Clear" is assumed.
40:             * The command class that is dispatched from this method returns the page that should be
41:             * displayed in response to the user request.  The command class that is dispatched from
42:             * this method is responsible for updating the request object with new attributes required by
43:             * the JSP page.
44:             *
45:             * @param request The servlet request object.
46:             * @param response The servlet response object.
47:             * @exception ServletException If problems occur with the request or rsponse.
48:             * @exception IOException If problems occur during request forwarding.
49:             */
50:            public void doPost(HttpServletRequest request,
51:                    HttpServletResponse response) throws ServletException,
52:                    IOException {
53:
54:                //Every request to this servlet must include the "CommandName" parameter.
55:                String commandName = request.getParameter(commandParameter);
56:                RequestDispatcher dispatcher;
57:
58:                // Start out with a cleared ErrorMessage attribute.
59:                request.setAttribute("errorMessage", "");
60:
61:                //If no commandName param, assume just "index.jsp" URL and initialize.
62:                if (commandName == null) {
63:                    commandName = "Clear";
64:                }
65:
66:                // Now try to dispatch to the command class responsible for handling the requested Command.
67:                try {
68:                    String commandClassName = "csdl.stackmvc.control.command."
69:                            + commandName + "Command";
70:                    Command command = (Command) Class.forName(commandClassName)
71:                            .newInstance();
72:                    Page page = command.process(request);
73:                    request.setAttribute("PageTitle", page.getTitle());
74:                    dispatcher = getServletContext().getRequestDispatcher(
75:                            page.getFileName());
76:                } catch (Exception e) {
77:                    request.setAttribute(exceptionAttribute, e);
78:                    dispatcher = getServletContext().getRequestDispatcher(
79:                            Page.ERROR.getFileName());
80:                }
81:
82:                // Now forward the updated request object on to the page that will be returned to the user.
83:                dispatcher.forward(request, response);
84:            }
85:
86:            /**
87:             * Dispatches to doPost for processing.
88:             *
89:             * @param request The servlet request.
90:             * @param response The servlet response.
91:             * @exception ServletException If problems during request/response processing.
92:             * @exception IOException If problems during the forward to the JSP page.
93:             */
94:            public void doGet(HttpServletRequest request,
95:                    HttpServletResponse response) throws ServletException,
96:                    IOException {
97:                doPost(request, response);
98:            }
99:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.