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
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 have a jsf web application. I use primefaces ver. 5.3 and pretty-faces ver. 3.3.3
I have a page, catalogue.xhtml, where there is a file uploader in primefaces:
<p:fileUpload onstart="start()" oncomplete="stop()" id="image" styleClass="#{!catalogueBean.form.headerInsert ? '' : 'hidden'}" auto="true"
fileUploadListener="#{catalogueBean.imageLoad}" mode="advanced" skinSimple="true" sizeLimit="10000000" allowTypes="/(\.|\/)(gif|jpe?g|png)$/"
update="imageOnline" />
My CatalogueBean:
#ManagedBean
#SessionScoped
#BeanPage(name = "/admin/catalogue")
public class CatalogueBean {
....
}
My pretty-config:
<pretty-config xmlns="http://ocpsoft.org/schema/rewrite-config-prettyfaces"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://ocpsoft.org/schema/rewrite-config-prettyfaces
http://ocpsoft.org/xml/ns/prettyfaces/rewrite-config-prettyfaces.xsd">
....
<url-mapping id="adminCatalogue">
<pattern value="/admin/catalogue" />
<view-id value="/page/admin/catalogue.xhtml" />
</url-mapping>
....
</pretty-config>
When I upload the file, I got no error, and the image is not uploaded.
I saw already other discussion, but them didn't solve my problem.
In particular I tried to add in my web.xml
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
where I declare PrimeFaces FileUpload Filter:
<filter-mapping>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<servlet-name>Faces Servlet</servlet-name>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
EDIT:
If I change the annotation in class CatalogueBean :
#BeanPage(name = "/page/admin/catalogue.xhtml")
in the console, after the upload, I see admin/catalog and I don't understand why...
Please let me know what I wrong, and if it's possible to map, for id = adminCatalogue, only calls in GET
Thanks
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.
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 am having some issues running a Struts web app since few days. I tried several solutions from StackOverflow relating to my problem but none of them works.
web.xml:
<display-name>Struts2 Application</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>Login.jsp</welcome-file>
</welcome-file-list>
struts.xml:
<struts>
<constant name="struts.enable.DynamicMethodInvocation"
value="false" />
<constant name="struts.devMode" value="false" />
<constant name="struts.custom.i18n.resources"
value="ApplicationResources" />
<package name="default" extends="struts-default" namespace="/">
<action name="login"
class="net.viralpatel.struts2.LoginAction">
<result name="success">Welcome.jsp</result>
<result name="error">Login.jsp</result>
</action>
</package>
</struts>
Login.jsp:
<%# page contentType="text/html; charset=UTF-8"%>
<%# taglib prefix="s" uri="/struts-tags"%>
<html>
<head>
<title>Struts 2 - Login Application | ViralPatel.net</title>
</head>
<body>
<h2>Struts 2 - Login Application</h2>
<s:actionerror />
<s:form action="login.action" method="post">
<s:textfield name="username" key="label.username" size="20" />
<s:password name="password" key="label.password" size="20" />
<s:submit method="execute" key="label.login" align="center" />
</s:form>
</body>
</html>
LoginAction.java:
package net.viralpatel.struts2;
public class LoginAction {
private String username;
private String password;
public String execute() {
if (this.username.equals("admin")
&& this.password.equals("admin123")) {
return "success";
} else {
return "error";
}
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
Libs I have added:
commons-logging-1.1.3.jar
freemarker-2.3.19.jar
ognl-3.0.6.jar
struts2-core-2.3.15.1.jar
xwork-core-2.3.15.1.jar
Error accessing URL:
http://localhost:8080/StrutsHelloWorld/
HTTP Status 404 - /StrutsHelloWorld/
type Status report
message /StrutsHelloWorld/
description The requested resource is not available.
Apache Tomcat/7.0.42
I tried this tutorial.
There are no errors on my console, problem view.
The error 404 means that resource you have requested is not available, the same referred to the action that is didn't map to the request URL.
FilterDispatcher is deprecated and may not work with the current Struts version, use StrutsPrepareAndExcecuteFilter instead.
<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>
in the struts.xml add the following
<package name="default" extends="struts-default" namespace="/">
<action name=""><result>/Login.jsp</result></acton>
this will forward you to the login page. Also consider to use absolute paths to the JSP resources.
In the JSP use the form that needs to rewrite to
<s:form namespace="/" action="login" method="post">
<s:textfield name="username" key="label.username" size="20" />
<s:password name="password" key="label.password" size="20" />
<s:submit key="label.login" align="center" />
</s:form>
In the action attribute use the action name and provide namespace as you did in the package configuration.
Using method="execute" is useless in the s:submit tag, the method execute used by default, and it will not work because you have turned off DMI in the Struts configuration.
Adding libraries over the old libraries in the WEB-INF/lib doesn't help so much and your application probably would not work, until you remove and replace all lower version libraries with higher version and add new libraries needed by the current version of Struts framework.
for me it's I didn't add "lang3" to library, after adding it everything goes well