pageInfo.setTrimDirectiveWhitespaces(JspUtil.booleanValue(jspProperty
.isTrimDirectiveWhitespaces()));
}
- if (jspProperty.getDefaultContentType() != null) {
- pageInfo.setContentType(jspProperty.getDefaultContentType());
- }
+ // Default ContentType processing is deferred until after the page has
+ // been parsed
if (jspProperty.getBuffer() != null) {
pageInfo.setBufferValue(jspProperty.getBuffer(), null,
errDispatcher);
// Pass 2 - the whole translation unit
pageNodes = parserCtl.parse(ctxt.getJspFile());
+ // Leave this until now since it can only be set once - bug 49726
+ if (pageInfo.getContentType() == null &&
+ jspProperty.getDefaultContentType() != null) {
+ pageInfo.setContentType(jspProperty.getDefaultContentType());
+ }
+
if (ctxt.isPrototypeMode()) {
// generate prototype .java file for the tag file
writer = setupContextWriter(javaFileName);
--- /dev/null
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jasper.compiler;
+
+import java.io.File;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.catalina.startup.Tomcat;
+import org.apache.catalina.startup.TomcatBaseTest;
+import org.apache.tomcat.util.buf.ByteChunk;
+
+public class TestCompiler extends TomcatBaseTest {
+
+ public void testBug49726a() throws Exception {
+ Tomcat tomcat = getTomcatInstance();
+
+ File appDir = new File("test/webapp-3.0");
+ tomcat.addWebapp(null, "/test", appDir.getAbsolutePath());
+ tomcat.start();
+
+ ByteChunk res = new ByteChunk();
+ Map<String,List<String>> headers = new HashMap<String,List<String>>();
+
+ getUrl("http://localhost:" + getPort() + "/test/bug49726a.jsp", res,
+ headers);
+
+ // Check request completed
+ String result = res.toString();
+ assertEcho(result, "OK");
+
+ // Check content type
+ assertTrue(headers.get("Content-Type").get(0).startsWith("text/html"));
+ }
+
+ public void testBug49726b() throws Exception {
+ Tomcat tomcat = getTomcatInstance();
+
+ File appDir = new File("test/webapp-3.0");
+ tomcat.addWebapp(null, "/test", appDir.getAbsolutePath());
+ tomcat.start();
+
+ ByteChunk res = new ByteChunk();
+ Map<String,List<String>> headers = new HashMap<String,List<String>>();
+
+ getUrl("http://localhost:" + getPort() + "/test/bug49726b.jsp", res,
+ headers);
+
+ // Check request completed
+ String result = res.toString();
+ assertEcho(result, "OK");
+
+ // Check content type
+ assertTrue(headers.get("Content-Type").get(0).startsWith("text/plain"));
+ }
+
+ /** Assertion for text printed by tags:echo */
+ private static void assertEcho(String result, String expected) {
+ assertTrue(result.indexOf("<p>" + expected + "</p>") > 0);
+ }
+}
Used as part of the Tomcat unit tests when a full web application is
required.
</description>
+ <jsp-config>
+ <jsp-property-group>
+ <default-content-type>text/plain</default-content-type>
+ <url-pattern>/bug49726a.jsp</url-pattern>
+ <url-pattern>/bug49726b.jsp</url-pattern>
+ </jsp-property-group>
+ </jsp-config>
</web-app>
\ No newline at end of file
--- /dev/null
+<%--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+--%>
+<%@ page contentType="text/html"%>
+<html>
+ <head><title>Bug 49726 test case</title></head>
+ <body>
+ <p>OK</p>
+ </body>
+</html>
+
--- /dev/null
+<%--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+--%>
+<html>
+ <head><title>Bug 49726 test case</title></head>
+ <body>
+ <p>OK</p>
+ </body>
+</html>
+
</add>
</changelog>
</subsection>
+ <subsection name="Jasper">
+ <changelog>
+ <fix>
+ <bug>49726</bug>: Specifying a default content type via a JSP property
+ group should not prevent a page from setting some other content type.
+ (markt)
+ </fix>
+ </changelog>
+ </subsection>
<subsection name="Cluster">
<changelog>
<fix>