Source Code Cross Referenced for ServletRedirectResult.java in  » Web-Framework » struts-2.0.11 » org » apache » struts2 » dispatcher » 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 » Web Framework » struts 2.0.11 » org.apache.struts2.dispatcher 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $Id: ServletRedirectResult.java 501746 2007-01-31 06:22:43Z mrdon $
003:         *
004:         * Licensed to the Apache Software Foundation (ASF) under one
005:         * or more contributor license agreements.  See the NOTICE file
006:         * distributed with this work for additional information
007:         * regarding copyright ownership.  The ASF licenses this file
008:         * to you under the Apache License, Version 2.0 (the
009:         * "License"); you may not use this file except in compliance
010:         * with the License.  You may obtain a copy of the License at
011:         *
012:         *  http://www.apache.org/licenses/LICENSE-2.0
013:         *
014:         * Unless required by applicable law or agreed to in writing,
015:         * software distributed under the License is distributed on an
016:         * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017:         * KIND, either express or implied.  See the License for the
018:         * specific language governing permissions and limitations
019:         * under the License.
020:         */
021:        package org.apache.struts2.dispatcher;
022:
023:        import javax.servlet.http.HttpServletRequest;
024:        import javax.servlet.http.HttpServletResponse;
025:
026:        import org.apache.commons.logging.Log;
027:        import org.apache.commons.logging.LogFactory;
028:        import org.apache.struts2.ServletActionContext;
029:        import org.apache.struts2.dispatcher.mapper.ActionMapper;
030:        import org.apache.struts2.dispatcher.mapper.ActionMapping;
031:
032:        import com.opensymphony.xwork2.ActionContext;
033:        import com.opensymphony.xwork2.ActionInvocation;
034:        import com.opensymphony.xwork2.inject.Inject;
035:
036:        /**
037:         * <!-- START SNIPPET: description -->
038:         *
039:         * Calls the {@link HttpServletResponse#sendRedirect(String) sendRedirect}
040:         * method to the location specified. The response is told to redirect the
041:         * browser to the specified location (a new request from the client). The
042:         * consequence of doing this means that the action (action instance, action
043:         * errors, field errors, etc) that was just executed is lost and no longer
044:         * available. This is because actions are built on a single-thread model. The
045:         * only way to pass data is through the session or with web parameters
046:         * (url?name=value) which can be OGNL expressions.
047:         *
048:         * <!-- END SNIPPET: description -->
049:         * <p/>
050:         * <b>This result type takes the following parameters:</b>
051:         *
052:         * <!-- START SNIPPET: params -->
053:         *
054:         * <ul>
055:         *
056:         * <li><b>location (default)</b> - the location to go to after execution.</li>
057:         *
058:         * <li><b>parse</b> - true by default. If set to false, the location param will
059:         * not be parsed for Ognl expressions.</li>
060:         *
061:         * </ul>
062:         *
063:         * <p>
064:         * This result follows the same rules from {@link StrutsResultSupport}.
065:         * </p>
066:         *
067:         * <!-- END SNIPPET: params -->
068:         *
069:         * <b>Example:</b>
070:         *
071:         * <pre><!-- START SNIPPET: example -->
072:         * &lt;result name="success" type="redirect"&gt;
073:         *   &lt;param name="location"&gt;foo.jsp&lt;/param&gt;
074:         *   &lt;param name="parse"&gt;false&lt;/param&gt;
075:         * &lt;/result&gt;
076:         * <!-- END SNIPPET: example --></pre>
077:         *
078:         */
079:        public class ServletRedirectResult extends StrutsResultSupport {
080:
081:            private static final long serialVersionUID = 6316947346435301270L;
082:
083:            private static final Log log = LogFactory
084:                    .getLog(ServletRedirectResult.class);
085:
086:            protected boolean prependServletContext = true;
087:
088:            protected ActionMapper actionMapper;
089:
090:            public ServletRedirectResult() {
091:                super ();
092:            }
093:
094:            public ServletRedirectResult(String location) {
095:                super (location);
096:            }
097:
098:            @Inject
099:            public void setActionMapper(ActionMapper mapper) {
100:                this .actionMapper = mapper;
101:            }
102:
103:            /**
104:             * Sets whether or not to prepend the servlet context path to the redirected URL.
105:             *
106:             * @param prependServletContext <tt>true</tt> to prepend the location with the servlet context path,
107:             *                              <tt>false</tt> otherwise.
108:             */
109:            public void setPrependServletContext(boolean prependServletContext) {
110:                this .prependServletContext = prependServletContext;
111:            }
112:
113:            /**
114:             * Redirects to the location specified by calling {@link HttpServletResponse#sendRedirect(String)}.
115:             *
116:             * @param finalLocation the location to redirect to.
117:             * @param invocation    an encapsulation of the action execution state.
118:             * @throws Exception if an error occurs when redirecting.
119:             */
120:            protected void doExecute(String finalLocation,
121:                    ActionInvocation invocation) throws Exception {
122:                ActionContext ctx = invocation.getInvocationContext();
123:                HttpServletRequest request = (HttpServletRequest) ctx
124:                        .get(ServletActionContext.HTTP_REQUEST);
125:                HttpServletResponse response = (HttpServletResponse) ctx
126:                        .get(ServletActionContext.HTTP_RESPONSE);
127:
128:                if (isPathUrl(finalLocation)) {
129:                    if (!finalLocation.startsWith("/")) {
130:                        ActionMapping mapping = actionMapper.getMapping(
131:                                request, Dispatcher.getInstance()
132:                                        .getConfigurationManager());
133:                        String namespace = null;
134:                        if (mapping != null) {
135:                            namespace = mapping.getNamespace();
136:                        }
137:
138:                        if ((namespace != null) && (namespace.length() > 0)
139:                                && (!"/".equals(namespace))) {
140:                            finalLocation = namespace + "/" + finalLocation;
141:                        } else {
142:                            finalLocation = "/" + finalLocation;
143:                        }
144:                    }
145:
146:                    // if the URL's are relative to the servlet context, append the servlet context path
147:                    if (prependServletContext
148:                            && (request.getContextPath() != null)
149:                            && (request.getContextPath().length() > 0)) {
150:                        finalLocation = request.getContextPath()
151:                                + finalLocation;
152:                    }
153:
154:                    finalLocation = response.encodeRedirectURL(finalLocation);
155:                }
156:
157:                if (log.isDebugEnabled()) {
158:                    log.debug("Redirecting to finalLocation " + finalLocation);
159:                }
160:
161:                response.sendRedirect(finalLocation);
162:            }
163:
164:            private static boolean isPathUrl(String url) {
165:                // filter out "http:", "https:", "mailto:", "file:", "ftp:"
166:                // since the only valid places for : in URL's is before the path specification
167:                // either before the port, or after the protocol
168:                return (url.indexOf(':') == -1);
169:            }
170:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.