Page Fragments, Entities and Characters

Switch to your JSP, and inside the body tag, type

One Piña Colada, Please!
If you run, you should see the expected text in the browser.

Now try the same thing, but edit the text inside a page fragment. If you deploy, you'll see this in the browser:

One Piña Colada, Please!

Uh oh! What happened?

Turns out the app server doesn't realize that the page fragment file, the jspf file, should be interpreted as an XML-formatted JSP, just like the main document. As a result, the source fragment file (which is just a static JSP include behind the scenes) gets, well, mistreated. You can see a very similar thing with entities. If you go and insert JSPX entities in your fragment, these will not be correctly expanded and instead of spaces you'll see things like " ".

Here's how you can fix this. You basically need to tell the deployment container that it needs to treat .jspf files as XML formatted JSPs. Unfortunately, you can only do that using JSP 2.0. That means this won't work on deployment containers that don't support JSP 2.0. The bundled one, Sun Application Server 8.1, does (as does 8.0 which we shipped with Creator 1.0, so this solution works for Creator 1.0 as well.)

Switch to the Files view (it's in the same window container as the project navigator), drill into your project, then open web/WEB-INF/web.xml. Switch to the XML view. Replace the root <webapp> element with the following:

<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
And then inside the body, insert the following:
  <jsp-config>
    <jsp-property-group>
      <url-pattern>\*.jspf</url-pattern>
      <is-xml>true</is-xml>
    </jsp-property-group>
  </jsp-config>

This is how this should look:

Now when you deploy, the page fragment text should be treated the way it's supposed to - and your Piña Colada will be on the way.

So why don't we just add this configuration info to the default web.xml we ship with Creator? Well, then you would no longer be able to use Creator with any older app servers. We're trying to hard to be compatible. However, we might be able to do something better here. I'll talk to Mr. Deployment to see what we can do.

Comments:

Hi, This solution seems to be very easy... But in fact, I have an issue with it: now my domain.xml file seems to be crashed, and as a result, I can't launch the sun java application server, even if I try to restore the web.xml file. Here are the last lines of the server.log file: > > =============================================== > java.util.logging.ErrorManager: 0: Error In getLogService com.sun.enterprise.config.ConfigException: Error refreshing ConfigContext:C:\\Creator\\SunAppServer8\\domains\\creator\\config\\domain.xml cause: Failed to create the XML-DOM Document. Check your XML to make sure it is correct. Attribute "context-root" is required and must be specified for element type "web-module". at com.sun.enterprise.config.ConfigContextImpl.refresh(ConfigContextImpl.java:315) at com.sun.enterprise.config.ConfigContextImpl.refresh(ConfigContextImpl.java:397) at com.sun.enterprise.config.ConfigContextImpl.getRootConfigBean(ConfigContextImpl.java:192) at com.sun.enterprise.config.ConfigBeansFactory.getConfigBeanByXPath(ConfigBeansFactory.java:36) at com.sun.enterprise.config.serverbeans.ServerBeansFactory.getServerBean(ServerBeansFactory.java:84) at com.sun.enterprise.config.serverbeans.ServerBeansFactory.getConfigModel(ServerBeansFactory.java:57) at com.sun.enterprise.config.serverbeans.ServerBeansFactory.getConfigBean(ServerBeansFactory.java:95) at com.sun.enterprise.server.logging.ServerLogManager.getLogService(ServerLogManager.java:281) at com.sun.enterprise.server.logging.FileandSyslogHandler.publish(FileandSyslogHandler.java:266) at java.util.logging.Logger.log(Logger.java:424) at java.util.logging.Logger.doLog(Logger.java:446) at java.util.logging.Logger.log(Logger.java:469) at com.sun.enterprise.server.logging.SystemOutandErrHandler$LoggingByteArrayOutputStream.flush(SystemOutandErrHandler.java:198) at java.io.PrintStream.write(PrintStream.java:260) at sun.nio.cs.StreamEncoder$CharsetSE.writeBytes(StreamEncoder.java:336) at sun.nio.cs.StreamEncoder$CharsetSE.implFlushBuffer(StreamEncoder.java:404) at sun.nio.cs.StreamEncoder.flushBuffer(StreamEncoder.java:115) at java.io.OutputStreamWriter.flushBuffer(OutputStreamWriter.java:169) at java.io.PrintStream.write(PrintStream.java:305) at java.io.PrintStream.print(PrintStream.java:448) at java.io.PrintStream.println(PrintStream.java:585) at com.sun.enterprise.server.logging.SystemOutandErrHandler$LoggingPrintStream.println(SystemOutandErrHandler.java:144) at java.lang.Throwable.printStackTraceAsCause(Throwable.java:492) at java.lang.Throwable.printStackTraceAsCause(Throwable.java:497) at java.lang.Throwable.printStackTrace(Throwable.java:468) at java.lang.Throwable.printStackTrace(Throwable.java:451) at java.util.logging.ErrorManager.error(ErrorManager.java:78) at com.sun.enterprise.server.logging.ServerLogManager.getLogService(ServerLogManager.java:284) at com.sun.enterprise.server.logging.ServerLogManager.initializeLogger(ServerLogManager.java:87) at com.sun.enterprise.server.logging.BaseLogManager.doInitializeLogger(BaseLogManager.java:108) at com.sun.enterprise.server.logging.BaseLogManager.addLogger(BaseLogManager.java:157) at java.util.logging.Logger.getLogger(Logger.java:231) at sun.rmi.runtime.Log$LoggerLogFactory.createLog(Log.java:154) at sun.rmi.runtime.Log.getLog(Log.java:135) at sun.rmi.server.UnicastRef.<clinit>(UnicastRef.java:50) at java.rmi.server.RemoteServer.<clinit>(RemoteServer.java:97) at com.sun.enterprise.admin.server.core.channel.AdminChannel.createServerObject(AdminChannel.java:188) at com.sun.enterprise.admin.server.core.channel.AdminChannel.createRMIChannel(AdminChannel.java:73) at com.sun.enterprise.admin.server.core.AdminService.init(AdminService.java:217) at com.sun.enterprise.admin.server.core.AdminServiceLifeCycle.onInitialization(AdminServiceLifeCycle.java:85) at com.sun.enterprise.server.ApplicationServer.onInitialization(ApplicationServer.java:220) at com.sun.enterprise.server.PEMain.run(PEMain.java:210) at com.sun.enterprise.server.PEMain.main(PEMain.java:172) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:324) at org.apache.commons.launcher.ChildMain.run(ChildMain.java:269) Caused by: org.netbeans.modules.schema2beans.Schema2BeansNestedException: Failed to create the XML-DOM Document. Check your XML to make sure it is correct. Attribute "context-root" is required and must be specified for element type "web-module". at org.netbeans.modules.schema2beans.GraphManager.createXmlDocument(GraphManager.java:718) at org.netbeans.modules.schema2beans.BaseBean.createGraph(BaseBean.java:2262) at com.sun.enterprise.config.ConfigContextImpl.refresh(ConfigContextImpl.java:293) ... 47 more Caused by: org.xml.sax.SAXParseException: Attribute "context-root" is required and must be specified for element type "web-module". at org.apache.xerces.parsers.DOMParser.parse(DOMParser.java:266) at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:206) at org.netbeans.modules.schema2beans.GraphManager.createXmlDocument(GraphManager.java:714) ... 49 more > ============================================== > > I'm working on winXP Pro. Why don't you seem to have the same matter?

Posted by Original Prankster on September 20, 2005 at 10:20 PM PDT #

hi Thank you for the entry. but it does not works. I have a jsf portlet build by creator 2 , when i add your code snippet to web.xml it say : Deploying application in domain failed; Error loading deployment descriptors for Advertiser Line 10 Column 111 -- Attribute "version" must be declared for element type "web-app". can you please clearify , whether this works with jsf portlet or not , what is my mistake that i return error

Posted by legolas woodland on January 13, 2006 at 07:15 PM PST #

Post a Comment:
Comments are closed for this entry.
About

Tor Norbye

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today