In my struts 2.3.16.1 application, after filter mapping in the web.xml "resource not found exception" occurs .Even the jsp pages in web directory also shows the same exception.
Thanks for your help in advance.
<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>
struts.xml
<?xml version="1.0" encoding="UTF-8"?>
<!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">
<action name="getTutorial" class="org.kishore.struts2.TutorialAction">
<result>/success.jsp</result>
</action>
</package>
</struts>
If your error is
type Status report
message /YourProjectName/success.jsp
description The requested resource is not available.
Then it means your success.jsp page is missing
And if message is blank and in console error is
Unable to load configuration. - action - file:/C:/Users/Parth/workspace1/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/serializ/WEB-INF/classes/struts.xml:7:75
then your class org.kishore.struts2.TutorialAction.java is missing
If you are getting following error
SEVERE: Dispatcher initialization failed Unable to load configuration. - bean - jar:file:/F:/apache-tomcat-6.0.39/wtpwebapps/struts2starter/WEB-INF/lib/struts2-portlet-plugin-2.3.16.1.jar!/struts-plugin.xml:31:133 at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:70)
Caused by: java.lang.ClassNotFoundException: javax.portlet.PortletMode
It means download Portlet Api 2.0.jar because without it you will not be able to use struts2-portlet-plugin-2.3.16.1.jar. If you do not add Portlet Api 2.0.jar you will continue getting error java.lang.ClassNotFoundException: javax.portlet.PortletMode
Note: Also make sure you are using compatible version of jars which have same version as struts-core-2.x.x.jar.
For example if you are using struts2-core-2.2.3.jar then you must use struts2-portlet-plugin-2.2,3.jar.
Related
This question already has answers here:
There is no Action mapped for namespace [/] and action name [login] associated with context path [/Struts2Test]
(4 answers)
Closed 2 years ago.
Currently migrating an app from Struts1 to Struts2.
When I click my "submit" button, it gives me an error saying "There is no Action mapped for action name requestInput". What is wrong with my code that is the cause of this error?
web.xml
<web-app>
<display-name>My Project</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>
<!-- The Usual Welcome File List -->
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
struts.xml
<struts>
<include file="struts-default.xml" />
<constant name="struts.custom.i18n.resources" value="global" />
<package name="default" namespace="/" extends="struts-default">
<interceptors>
<interceptor-stack name="uploadFile">
<interceptor-ref name="fileUpload" />
<interceptor-ref name="uploadForm" />
<interceptor-ref name="modelDriven" />
<interceptor-ref name="basicStack" />
</interceptor-stack>
</interceptors>
<action name="requestInput" class="com.class.action.FileAddAction" method="execute">
<result>/result.jsp</result>
</action>
</package>
</struts>
FileAdd.jsp
<s:form method="POST" action="requestInput" enctype="multipart/form-data">
...
<s:submit property="submit" style="background:#dccaa0" value="Submit" theme="simple"/>
...
</s:form>
FileAddAction.jsp
public final class FileAddAction extends ActionSupport implements SessionAware, ServletRequestAware {
...
public String execute() throws Exception{
...
}
}
And, my struts.xml is in the Java src folder and in the WEB-INF folder.
What else can I do to fix this? Thanks..
Two issues, otherwise looks good.
First issue:
action name="requestInput" class="com.class.action.FileAddAction"
method="execute"
You can't name your package with the identifier class, it is not a valid Java identifier
Second issue:
interceptor-ref name="uploadForm"
What is "uploadForm"? It's definitely not provided by Struts 2, see the list.
By naming the package differently, and removing interceptor-ref uploadForm, i am able to click the FileAdd.jsp Submit button without any issue and it is redirecting me successfully to result.jsp. I used v2.3.37.
Note:
struts.xml should be in the src/main/resources folder (struts.xml must be on the web application’s root class path). Check this out.
web.xml is to be under src/main/webapp/WEB-INF folder. Check this out.
I've tried to create a new action class and add it to struts.xml, the action class successfully get compiled but when I run tomcat it shows The requested resource is not available 404 error on index page itself.
CreateUser.jsp
<s:form action = "CreateUserAction" >
<s:textfield name = "name" label = "Name" />
<s:textfield name = "userName" label = "User Name" />
<s:submit value = "Register" />
</s:form>
CreateUserAction.java
public String execute() {
setMessage("Hello " + getUserName());
return "SUCCESS";
}
Struts.xml
<package name="default" extends="struts-default">
<action name="CreateUserAction" class="com.ecommerce.action.CreateUserAction">
<result name="SUCCESS">/success.jsp</result>
</action>
</package>
Actions in Struts2 are mapped to the URLs that are built from the configuration. When the url of the request match the action name and namespace then it is executed, otherwise error code 404 is returned by the dispatcher. Struts2 is implemented as a filter and it's looking for the requests that are mapped in it's configuration. For example if I want it to filter all URLs I will write in web.xml
<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>
If you say the error 404 on index page itself, then you should ask yourself which URL corresponds to it and what action is mapped via configuration to that URL. If you need more detailed picture of what configuration is and what URLs you could enter to execute an action install the config-browser plugin.
for the above issue:"The requested resource is not available in struts2 when action class is configured in struts.xml"
I have a suggestion.
Copy and paste all the external jars in in the folder lib(WebContent-->WEB-INF-->lib)
remove all external jars from Build path (Project -->buildpath-->Configure Build path)
I found this solution is working fine for eclipse Luna with Tomacat 7
I have a project using struts 2.1.8. The project is configured by annotation using struts2-convention-plugin. Here is my struts config in web.xml:
<filter>
<filter-name>struts2Filter</filter-name>
<filter-class>
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2Filter</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>struts2Filter</filter-name>
<url-pattern>/struts/*</url-pattern>
</filter-mapping>
struts.xml:
<constant name="struts.convention.default.parent.package" value="borrow-default" />
<constant name="struts.convention.package.locators" value="action" />
<constant name="struts.convention.package.locators.basePackage" value="com.abc.action" />
<constant name="struts.convention.result.path" value="/" />
A.java:
#Namespace("/regist")
public class A extends ActionSupport{
#Action(value="/a", results = {#Result(location = "/a/test.jsp")})
public String execute(){
return SUCCESS;
}
}
Here is the problem, I can access the test.jsp in url http://localhost:8080/a/test.jsp and http://localhost:8080/regist/a.action, but I can still visit the same page in url http://localhost:8080/a/test.action. I don't know why this happens, what's wrong in my config or code?
I also tried some other url, it seems the namespace doesn't take effect.
In web.xml your url pattern is like:
<url-pattern>/struts/*</url-pattern>
but you are placed jsp and getting it from /a/test.jsp
once check it...
I upgraded the struts to 2.3.15.1 and this question disappeared
I want to add an action to my struts.xml but when I do it my webapp stop to work and I don't know why. I post here some details of my webapp.
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/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>ILIMobileLeborgne</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.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
struts.xml (in the src folder in Eclipse):
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constant name="struts.devMode" value="true" />
<constant name="struts.custom.i18n.resources" value="ilimobile" />
<package name="ilimobile" namespace="/" extends="struts-default">
<action name="index">
<result>/index.jsp</result>
</action>
<action name="registerIllimite">
<result>/registerIllimite.jsp</result>
</action>
<!-- When i try to do add the following action my app doesn't working, the browser said me that the ressource asked is unavailable and when i delete it my (little) app works correctly -->
<action name="registerClientInfo" class="action.SubscribeAction">
<result name="success">/paiement.jsp</result>
</action>
</package>
</struts>
my SubscribeAction (in the action package in the source folder) :
package action;
import model.*;
import com.opensymphony.xwork2.ActionSupport;
public class SubscribeAction extends ActionSupport {
private Client client;
private String abonnement;
public String getAbonnement() {
return abonnement;
}
public void setAbonnement(String abonnement) {
this.abonnement = abonnement;
}
#Override
public String execute() throws Exception {
// TODO Auto-generated method stub
return SUCCESS;
}
public Client getClient() {
return client;
}
public void setClient(Client client) {
this.client = client;
}
}
And my JSP page which use the action defined :
<%# page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%# taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<s:form action="registerClientInfo">
<s:textfield key="client.nom"/>
<s:textfield key="client.prenom"/>
<s:textfield key="client.email"/>
<s:textfield key="client.adresse"/>
<s:textfield key="client.ville"/>
<s:textfield key="client.cp"/>
<s:submit/>
</s:form>
</body>
</html>
If you need some extra info ask me but i think you could see why my app doesn't want to work :/ I'm pretty sure that it's just a little error but i can't find it...
Thanks for all and have a happy new year party :)
(Sorry for my English I'm a french student ^^)
Edit : I post here the Eclipse stack trace which show me that he can't find my action class but i don't know why :/ I've a struts example made by my teacher and i don't think that he made some extra steps to deploy the app with a tomcat server on Eclipse
The stack trace :
Unable to load configuration. - action - file:/home/blackmario/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/ILIMobileLeborgne/WEB-INF/classes/struts.xml:20:68
at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:70)
at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:429)
at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:471)
at org.apache.struts2.dispatcher.ng.InitOperations.initDispatcher(InitOperations.java:74)
at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.init(StrutsPrepareAndExecuteFilter.java:51)
at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:277)
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:258)
at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:382)
at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:103)
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4650)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5306)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
Caused by: Action class [action.SubscribeAction] not found - action - file:/home/blackmario/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/ILIMobileLeborgne/WEB-INF/classes/struts.xml:20:68
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.verifyAction(XmlConfigurationProvider.java:480)
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.addAction(XmlConfigurationProvider.java:424)
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.addPackage(XmlConfigurationProvider.java:541)
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.loadPackages(XmlConfigurationProvider.java:290)
at org.apache.struts2.config.StrutsXmlConfigurationProvider.loadPackages(StrutsXmlConfigurationProvider.java:112)
at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:239)
at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:67)
... 18 more
So, it sounds like your application fails to start when you add that action, correct? Nothing works, even the ones that worked before. So, you should look in the logs of the servlet container you are using. Nothing is more fundamental that finding where the logs are and becoming familiar with them.
When you do look in the logs, I'm guessing you'll see either
1) an error complaining that the syntax of the struts.xml is bad and the application fails when trying to parse it.
or
2) A ClassNotFoundException because the class file for that action is not on the classpath of the application. If this is the case make sure that the class files for that action are actually being put into the WAR file's WEB-INF/lib or WEB-INF/classes direcgtory; that's where a webapp's classloader looks for class files. If you don't know much about this, you should read more about Java Servlets.
Both of these are things that might cause the application to not successfully start. You must look at the logs; they will amost always tell you that the application had a specific issue. If you ask about that specific issue on this forum, you'll get very useful answers. Otherwise, I'm kind of guessing.
By default .action extension is used by the struts-default package that you extend. When you place the url in the browser make sure you have use correct url.
Try changing
<action name="registerClientInfo" class="action.SubscribeAction">
<result name="success">/paiement.jsp</result>
</action>
to
<action name="registerClientInfo" class="SubscribeAction">
<result name="success">/paiement.jsp</result>
</action>
I am using struts2 for developing a web application.
I have include the required jars for struts2 but when it is going to call the struts action class it is throwing 404 error.
There is no error on console and browser does not showing .action extension whitch it shows when struts.xml call an action class.
I am using jdk 1.6 and struts 2.0.
Am I missing any jar who is responsible for all this.
In jsp I am simply calling the function from
<s:form action = "Mergexmlaction" method = "post"/>
Here is my struts.xml and web.xml
struts.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constant name="struts.multipart.maxSize" value="6000000000" />
<package name="default" namespace="/jsp" extends="struts-default">
<action name="Mergexmlaction" class="com.hm.merge.mergeaction.Mergexmlaction">
<result name="success" >/jsp/Result.jsp</result>
<result name="error" >/jsp/Browse_multiplexmlfiles.jsp</result>
<interceptor-ref name="fileUpload">
<param name="maximumSize">600000000</param>
</interceptor-ref>
</action>
</package>
</struts>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="xml_file_merging" 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>xml_file_merging</display-name>
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.FilterDispatcher
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>jsp/Browse_multiplexmlfiles.jsp</welcome-file>
</welcome-file-list>
</web-app>
There are a few issues.
<package name="default" namespace="/jsp" extends="struts-default">
1) I'd recommend against having a namespace of "jsp", it doesn't make any sense. Namespaces should be something meaningful to the application and/or user.
<action name="Mergexmlaction" class="com.hm.merge.mergeaction.Mergexmlaction">
2) Don't name an action with "action", there will either be a .action extension, or no extension at all. Either way, there's no reason to duplicate "action" in the first case, and no reason to use "action" if there's no extension. Just "mergexml", "mergeXml", etc.
<result name="success" >/jsp/Result.jsp</result>
3) I recommend putting your JSP pages under WEB-INF to avoid direct client access.
<interceptor-ref name="fileUpload">
4) Once you declare any interceptors, you must declare all interceptors. This action has only a single interceptor running. It's possible this is okay, but it's almost never the right thing to do.
<welcome-file>jsp/Browse_multiplexmlfiles.jsp</welcome-file>
5) And this is the ultimate issue, depending on how you're accessing the application. You show the welcome file as being a JSP page, which is presumably using S2 tags. This won't work: the tags depend on their being a complete S2 request, a value stack, etc.
All access to an S2 app should take place through an S2 action, not a JSP. If you look at the rendered HTML for the directly-accessed JSP you'll see neither namespace nor action extension rendered.
an error 404 is a bad link. means you just are calling a link that doesnt exist. Check your mapping in your struts config file and make sure you use the correct url.
The namespace attribute of package element is optional and if it is not present, the default value "/" is assumed. If the namespace attribute has a non-default value, the namespace must be added to the URI that invokes the actions in the package.
For example, the URI for invoking an action in a package with a default namespace is this:
/context/actionName
To invoke an action in a package with a non-default namespace, you need this URI:
/context/namespace/actionName