If I am not including web.xml file then index file is opening properly but result page HelloWorld.jsp is giving 404 error, and when including web.xml index page is giving 404 error.
I have index.jsp file. localhost:8080 is working correctly but after that it is giving error.
See here:
In the first case the index file is opened by the default servlet, that is available on the server.
In the second case you use FilterDispatcher that is deprecated.
You should upgrade Struts to the latest version and use
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
See how to write web application descriptor web.xml.
Simple Example
Configuring web.xml for the framework is a matter of adding a filter
and filter-mapping.
FilterDispatcher Example (web.xml):
<web-app id="WebApp_9" 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">
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- ... -->
</web-app>
Related
I am in the process of migrating Struts 2+Jsf 2.x web application from WEB -LOGIC 10.3.3.0 to 12.1.3.0.
I am encountering an error while accessing the pages ,as per my understanding if a JSF tag encounters with a value which is reading from the properties file it is encountering the Issue.And in the same pages I am able to read the struts messages.
I have created a POC with the same jars which my application is using to check the JSF is rendering properly or not.the POC is working fine.
and I placed the POC created page in to my application and tried to access again the same error encounterd.
when I comment the Struts filter in My application ,newly created pages worked fine.
I have tried to upgrade the Struts2jsf plugin.jar to newer versions .
I have removed the jsf-api,jsf -impl,JSTL from the APPINF\LIB.
changed the faces-config xsd to 2.0
but no luck..
Below is the error stack :
java.lang.stackOverflowError.
at java.util.HasMap$treeNode.GetTreeNode(HashMap.java:1873)
at java.util.HasMap.getNode(HashMap.java:573)
at java.util.HashMap.get(HashMap.java:556)
at ognl.ognlRuntime.getParameterTypes(ognlRuntime.java)
at ognl.ognlRuntime.findParameterTypes(ognlRuntime.java)
at ognl.OgnlRuntime.getGetMethod(ognlRuntime.java)
at ognl.ognlRuntime.hasGetMethod(ognlRuntime.java)
....
at org.apache.struts2.jsf.strutsVariableResolver.resolvervariable(StrutsVaraibaleResolver :78)
at com.sun.faces.el.variabelResolverImpl.resolvervariabel(VariableResolverImpl.java:80))
at org.apache.struts2.jsf.strutsVariableResolver.resolvervariable(StrutsVaraibaleResolver :78)
at com.sun.faces.el.variabelResolverImpl.resolvervariabel(VariableResolverImpl.java:80))
at org.apache.struts2.jsf.strutsVariableResolver.resolvervariable(StrutsVaraibaleResolver :78)
at com.sun.faces.el.variabelResolverImpl.resolvervariabel(VariableResolverImpl.java:80))
at org.apache.struts2.jsf.strutsVariableResolver.resolvervariable(StrutsVaraibaleResolver :78)
at com.sun.faces.el.variabelResolverImpl.resolvervariabel(VariableResolverImpl.java:80))
java.lang.ClassCastException:java.lang.StackOverflowerror cannot be cast to java.lang.Excetption
java.lang.ClassCastException:java.lang.StackOverflowerror cannot be cast to java.lang.Excetption
at jsp_servlet._error._jspService(_error.java)
at weblogic.servlet.jsp.Jspbase.service(JsPBase.java)
**
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app
version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-Value>classpath:/applicationContext-resources.xml
classpath:/applicationContext-dao.xml
classpath:/applicationContext-service.xml
/WEB-INF/applicationContext.xml
/WEB-INF/applicationContext-Struts.xml
/WEB-INF/Secuirty.xml
</param-Value>
</context-param>
<context-param>
<param-name>javax.faces.DISABLE_FACELET_JSF_VIEWHANDLE</param-name>
<param-value>false</param-value>
</context-param>
<listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>
<servlet>
<servlet-name>faces</servlet-name/>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class/>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>faces</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>JSPSupportServlet</servlet-name>
<servlet-class>org.apache.struts2.views.JspSupportServlet</servlet-class>
</servlet>
<filter>
<filter-name>struts-prepare</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareFilter</filter-class>
</filter>
<filter>
<filter-name>struts</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsExecuteFilter</filter-class>
</filter>
<filter>
<filter-name>sitemesh</filter-name>
<filter-class>com.opensymphone.module.sitemesh.filter.PageFilter</filter-class>
</filter>
<filter>
<display-name>richfaces</display-name>
<filter-name>richfaces</filter-name>
<filter-class>org.ajax4jsf.Filter</filter-class>
</filter>
<filter-mapping>
<filter-name>sitemesh </filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD </dispatcher>
<dispatcher>INCLUDE </dispatcher>
</filter-mapping>
<filter-mapping>
<filter-name>struts </filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>richfaces</filter-name>
<url-pattern>*.html</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
<dispatcher>INCLUDE</dispatcher>
</filter-mapping>
<filter-mapping>
<filter-name>sitemesh </filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
faces-config.xml :
<?xml version="1.0" encoding="UTF-8"?>
<faces-config
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd"
version="1.2"
<application>
<locale-config>
<default-locale>en</default-locale>
</locale-config>
<resource-bundle>
<base-name>message</base-name>
<var>msg</var>
</resource-bundle>
</application>
I have added additionally to the faces config below handler which worked me to display the login page
<view-handler>org.ajax4jsf.application.AjaxViewHandler</view-handler>
while navigating to any page above error encountering.
Below are the list of jars presented :
activation-1.1.jar
antlr-2.7.6.jar
aopaliance-1.0.jar
asm3.3.jar
aspectjrt-1.6.6.jar
aspectjweaver-1.6.6.jar
axiom-api-1.2.5.jar
cglib-2.2.jar
commons-beanutils-1.7.0.jar
commons-Codec-1.5.jar
Commons-collections-3.2.jar
commons-digester-1.8.jar
commons-el.jar
commons-fileupload-1.2.1.jar
commons-io-1.4.jar
commons-lang-2.4.jar
commong-logging-1.1.1.jar
commons-pool-1.2.jar
commons-vfs-1.0.jar
compass-2.1.3.jar
jsf-facelets 1.1.15B1.jar
richfaces-impl 3.3.jar
richfaces-ui 3.3Final.jar
standard.jar
jstl.jar
jsf-api2.0.2.jar
jsf-impl 2.0.2.jar
log4j-1.2.13 jar
ognl2.7.3.jar
sitemesh-2.4.2.jar
richfaces-api-3.3.3.Final.jar
richfaces-imple-jsf2-3.3.3.Final.jar
richfaces-ui-3.3.3.Final.jar
slf4j-api.jar
slf4j-log4j12.jar
hibernate-core.jar
hibernate-search.jar
hibernate-commons-annotations.jar
hibernate-annotations.jar
standard1.1.2.jar
struts2-corre-2.1.8.jar
struts2-jsf-plugin-2.1.8.1
wsdl4j-1.6.2.jar
xml-apis-1.0.b2.jar
xml-resolver-1.2.jar
xmlbeans-2.4.0.jar
xmlSchema-core 2.0.jar
xwork-core2.1.6.jar
etc...
eg code causing the errors :
hello.jsp
<%# taglib prefix="h" uri="http://java.sun.com/jsf/html" %>
<%# taglib prefix="f" uri="http://java.sun.com/jsf/core" %>
<head>
<title>JSF Example</title>
<head>
<body>
<h2>JSF Example - </h2>
<h:form>
<h:inputText value="#{msg.testmessage}"></h:inputText>
</h:form>
<body>
</html>
I am struggling a lot what went wrong.and the application is running fine in wls 10.3.3.0.
appreciated your help.
Regards,
Ganesh Karanam
I stumbled upon an issue in my jsf spring application.
After a successfull setup i added spring security to my application and suddenly the injection of #ManagedProperty in jsf beans stopped working. More specifically it turns that properties injected like this are null when using them.
I am using jsf 2.1, spring 3.1 (core + security)
The config looks like this:
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
<welcome-file-list>
<welcome-file>index.jsf</welcome-file>
</welcome-file-list>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<listener>
<listener-class>
org.springframework.web.context.request.RequestContextListener
</listener-class>
</listener>
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/log4j.properties</param-value>
</context-param>
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-security-context.xml</param-value>
</context-param>
</web-app>
FacesServlet is the default servlet dispatcher.
in the faces config i added
<application>
<el-resolver>
org.springframework.web.jsf.el.SpringBeanFacesELResolver
</el-resolver>
</application>
...
The jsf managed bean looks like this:
#ManagedBean
public class InterviewForm {
#ManagedProperty (value="#{springInterviewHelper}")
private SpringInterviewHelper springInterviewHelper;
...
The springInterviewHelper ends null with the springSecurityFilterChain added in web.xml. If i remove that filter all is working fine, except for the fact that i cannot make use of spring security :). Checked with debug and the only modifications in the stack trace are related to the security filtering so this might cause the injection failure.
I'd like to use, if possibly, the jsf annotations and not those of spring because i can make use of #ViewScoped and other cosy things of jsf managed beans. Is this possible? What could cause the injection failure?
Thanks a lot,
Marius
The ContextLoaderListener by default loads an xml file called applicationContext.xml from inside the WEB-INF directory. As soon as you specify a context-param named contextConfigLocation this default doesn't apply anymore. Also see the reference guide.
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-security-context.xml</param-value>
</context-param>
The configuration above will lead to loading ONLY the mentioned configuration file, it will not load the applicationContext.xml file anymore. Now you can solve this easily by simply adding the aformentioned file to the param-value tag.
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml,/WEB-INF/spring-security-context.xml</param-value>
</context-param>
That should do the trick.
I need to integrate pretty faces with my jsf 2.0, primefaces application, but its giving some troubles.
As mentioned in the getting started i placed following in my web.xml, added the required jar in the lib folder
<filter>
<filter-name>Pretty Filter</filter-name>
<filter-class>com.ocpsoft.pretty.PrettyFilter</filter-class>
<async-supported>true</async-supported>
</filter>
<filter-mapping>
<filter-name>Pretty Filter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>FORWARD</dispatcher>
<dispatcher>REQUEST</dispatcher>
<dispatcher>ERROR</dispatcher>
</filter-mapping>
other items in my web.xml
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<context-param>
<param-name>com.sun.faces.expressionFactory</param-name>
<param-value>org.jboss.el.ExpressionFactoryImpl</param-value>
</context-param>
<context-param>
<param-name>org.primefaces.extensions.DELIVER_UNCOMPRESSED_RESOURCES</param-name>
<param-value>false</param-value>
</context-param>
But i am getting following Error:
Invalid content was found starting with element 'async-supported'. One of '{"http://java.sun.com/xml/ns/javaee":init-param}' is expected
If i remove <async-supported> from the project builds, project compiles but the mapping doesnt work.
pretty-config.xml is same as in the getting started.
Do i need to mention in my web.xml the name/path of the mapping file i.e pretty-config.xml?
EDIT:
I am using Glassfish server 3.
It is very important to check the version attribute you are using in your web.xml. If you have version="2.5" set, you have to add this to your web.xml:
<filter>
<filter-name>Pretty Filter</filter-name>
<filter-class>com.ocpsoft.pretty.PrettyFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>Pretty Filter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>FORWARD</dispatcher>
<dispatcher>REQUEST</dispatcher>
<dispatcher>ERROR</dispatcher>
</filter-mapping>
Please not that <async-supported>true</async-supported> is NOT set here, because it is only supported in Servlet 3.0.
If you have version="3.0" set in your web.xml, you don't have to add anything to your web.xml. In this case PrettyFaces automatically registers the filter using the web-fragment.xml that is included in prettyfaces-jsf2.jar.
You don't have to specify the location of pretty-config.xml anywhere. Just place it in your WEB-INF folder and PrettyFaces will find it.
You should also add one mapping to your pretty-config.xml, so you can check if everything works correctly. If you have for example a page that you typically access using an URL like:
http://localhost:8080/myapp/faces/login.xhtml
Then you can add this mapping:
<url-mapping id="login">
<pattern value="/login" />
<view-id value="/faces/login.xhtml" />
</url-mapping>
Now you should be able to access the page using this link:
http://localhost:8080/myapp/login
I am using warbler to create war of my Jruby application. It creates a war without any problem, but when I deploy it in tomcat (webapps) it gives me following exception:
SEVERE: Parse error in application web.xml file at jndi:/localhost/POC_Rails_1_3_1_/WEB-INF/web.xml
org.xml.sax.SAXParseException: Comment must start with "<!--".
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1231)
Generated (WEB-INF/web.xml) is below. Let me know if I have forgotten to configure something.
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<context-param>
<param-name>public.root</param-name>
<param-value>/</param-value>
</context-param>
<context-param>
<param-name>rails.env</param-name>
<param-value>developement</param-value>
</context-param>
<filter>
<filter-name>RackFilter</filter-name>
<filter-class>org.jruby.rack.RackFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>RackFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
<listener-class>org.jruby.rack.rails.RailsServletContextListener</listener-class>
</listener>
</web-app>
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<context-param>
<param-name>public.root</param-name>
<param-value>/</param-value>
</context-param>
<context-param>
<param-name>rails.env</param-name>
<param-value>developement</param-value>
</context-param>
<filter>
<filter-name>RackFilter</filter-name>
<filter-class>org.jruby.rack.RackFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>RackFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
<listener-class>org.jruby.rack.rails.RailsServletContextListener</listener-class>
</listener>
</web-app>
As the first commentor mentioned the xml is invalid because of duplicate <web-app> and <!DOCTYPE. The parser error is related to <!. <! is meant for declaring documenttype and it can appear only before the start of the root element. Any subsequent appearances will be treated as start of a comment. And the comment needs -- after <!
I have a simple Struts2 app that is serving JSP files just fine. But when I try to serve CSS files, I get 404.
Here is my web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
In my WEB-INF I have a content folder where I serve JSP files (using the convention plugin). I tried putting a css\application.css folder/file in both the content and web-inf root directly. Neither work.
Any tips would be appreciated.
Thanks
Nevermind. I figured it out. I had the folder in the wrong location.
It needed to be directly in the web folder and not WEB-INF.
Dur...