I am using strust2 for my web application development. My struts.xml file will be like:
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="default" extends="struts-default" namespace ="/">
<action name="signup">
<result>/check.jsp</result>
</action>
</package>
</struts>
and my web.xml file will be something like:
<?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/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>sample</display-name>
<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>
<servlet>
<servlet-name>My WS</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>com.dr1.dr2</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>My WS</servlet-name>
<url-pattern>/checking</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
and now,
if i access like: http://localhost:8080/appName/ its going to my signup action perfectly.
But when i tried to access like http://localhost:8080/appName/checking (for webservices), Its even looking in struts.xml and getting an error message like:
HTTP Status 404 - There is no Action mapped for namespace / and action name checking...
even after defining this in web.xml..
Is there any way to exclude a pattern in struts2, so that when I hit http://localhost:8080/appName/checking, it must not look struts action, it must call my default page path defined in web.xml file.
Thanks..
you can probably add exclude pattern in your struts.xml, something like
<struts>
<constant name="struts.action.excludePattern" value="appName/checking"/>
</struts>
read here and find excludePattern for more information.
this could works:
<!-- exclude pattern -->
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/struts/*</url-pattern>
</filter-mapping>
an action exampe:
<constant name="struts.action.excludePattern" value="appName/checking"/>
the constant excludePattern explicit exclusions (since 2.1.7)
Related
Project Structure in Eclipse
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
id="WebApp_ID" version="3.1">
<display-name>Struts2Starter</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
struts.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
"http://struts.apache.org/dtds/struts-2.5.dtd">
<struts>
<package name="default" extends="struts-default">
<action name="getTutorial" class="org.awanish.action.TutorialAction">
<result name="success">/success.jsp</result>
<result name="error">/error.jsp</result>
</action>
</package>
</struts>
ActionClass
package org.awanish.action;
public class TutorialAction {
public String execute() {
System.out.println("Hello from execute");
return "success";
}
}
When running the above project in tomcat-8.0.43 container, getting my welecome page but when tried to test the action in browser http://localhost:8080/Struts2Starter/getTutorial.action it gives this
Error in browser
1.check in logs if:Hello from execute is printed
2. check if the jsp exists in the correct path
3. .action is not required at the end
4.<action name="getTutorial" class="org.awanish.action.TutorialAction" method="define your own method and try calling it">
5.Add jars at runtime also inside WEB-INF/lib folder
http://localhost:8080/Struts2Starter/getTutorial
And if you begineer try using struts 2.3 rather than struts 2.5 ,you will get lots of example:https://www.mkyong.com/struts2/struts-2-hello-world-example/
Download code and build on top of it if still facing issue
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 have two web applications (web-module1.war & web-module2.war) and I want to use a web fragment (web-core.jar) for common servlet declaration like FacesServlet.
When I declare FacesServlet in web.xml no problem, but when I move this declaration to web-fragment.xml I get this error :
java.lang.IllegalStateException: No Factories configured for this Application.
This happens if the faces-initialization does not work at all - make sure that you properly include all configuration settings necessary for a basic faces application and that all the necessary libs are included. Also check the logging output of your web application and your container for any exceptions!
If you did that and find nothing, the mistake might be due to the fact that you use some special web-containers which do not support registering context-listeners via TLD files and a context listener is not setup in your web.xml.
A typical config looks like this;
<listener>
<listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class>
</listener>
I don't have this problem with other servlet/filter declaration !
The web-fragment.xml is in web-core.jar's META-INF folder as well as the faces-config.xml.
The web-core.jar is declared as a maven dependency (I can find it in the WEB-INF/lib).
This is web.xml :
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" metadata-complete="false"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
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_3_0.xsd">
<absolute-ordering>
<name>core_web_fragment</name>
</absolute-ordering>
</web-app>
And web-fragment.xml :
<?xml version="1.0" encoding="UTF-8"?>
<web-fragment metadata-complete="true" version="3.0"
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-fragment_3_0.xsd">
<name>core_web_fragment</name>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-*.xml</param-value>
</context-param>
<!-- /Spring Config -->
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<context-param>
<param-name>javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL</param-name>
<param-value>true</param-value>
</context-param>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>inscription.xhtml</welcome-file>
</welcome-file-list>
</web-fragment>
I'm using Tomcat7
If you are using Apache Myfaces JSF implementation this is a known bug
So u should change it ( use MOJARRA for example)
Can some one help me on how to exclude decoration of child window? Here is my code:
web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" 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">
<display-name>Hello World Struts 2 Maven</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<listener>
<listener-class>org.apache.struts2.dispatcher.ng.listener.StrutsListener</listener-class>
</listener>
<!--Filters -->
<filter>
<filter-name>struts-cleanup</filter-name>
<filter-class>org.apache.struts2.dispatcher.ActionContextCleanUp</filter-class>
</filter>
<filter>
<filter-name>struts-prepare</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareFilter</filter-class>
</filter>
<filter>
<filter-name>struts-execute</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsExecuteFilter</filter-class>
</filter>
<filter>
<filter-name>sitemesh</filter-name>
<filter-class>com.opensymphony.module.sitemesh.filter.PageFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts-prepare</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
<filter-mapping>
<filter-name>sitemesh</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
<filter-mapping>
<filter-name>struts-execute</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
<filter-mapping>
<filter-name>struts-cleanup</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
</web-app>
struts.xml:
<struts>
<constant name="struts.devMode" value="true" />
<package name="basicstruts2" extends="struts-default">
<!-- If no class attribute is specified the framework will assume success and
render the result index.jsp -->
<!-- If no name value for the result node is specified the success value is the default -->
<action name="index">
<result>/index.jsp</result>
</action>
<action name="child3">
<result>/WEB-INF/popUp/Test.jsp</result>
</action>
<!-- If the URL is hello.action the call the execute method of class HelloWorldAction.
If the result returned by the execute method is success render the HelloWorld.jsp -->
<action name="hello" class="org.apache.struts.helloworld.action.HelloWorldAction" method="execute">
<result name="success">/HelloWorld.jsp</result>
</action>
</package>
</struts>
decorators.xml:
<?xml version="1.0" encoding="ISO-8859-1"?>
<decorators defaultdir="/decorators">
<excludes>
<pattern>/WEB-INF/popUp/Test.jsp</pattern>
<pattern>/popUp/Test.jsp</pattern>
<pattern>child3.html</pattern>
<pattern>child3</pattern>
<pattern>/default/child3</pattern>
<pattern>/default/child3.html</pattern>
</excludes>
<decorator name="main" page="layout.jsp">
<pattern>/*</pattern>
</decorator>
<decorator name="panel" page="panel.jsp" />
</decorators>
I have already spent 2 days on this task and not succeeded yet. Can anyone help or point to me to some links?
Regards,
Nazir
I solved the problem. I added struts2-sitemesh plugin and followed the documentation on configuring the web xml. Now my decorators are working well.
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...