I am working on struts2-archetype-starter. Got a demo struts 2 project by executing:
mvn archetype:generate -B -DgroupId=demoStrutsStarter -DartifactId=DemoStrutsStarter -DarchetypeGroupId=org.apache.struts -DarchetypeArtifactId=struts2-archetype-starter
I modified my struts.xml and added a struts.action.extension constant declaration. Now it looks like this:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<constant name="struts.action.extension" value=","/>
<constant name="struts.enable.DynamicMethodInvocation" value="false"/>
<package name="myPackage" extends="struts-default">
<default-action-ref name="index" />
<action name="index" class="demoStrutsStarter.IndexAction">
<result>/jsp/index.jsp</result>
</action>
<action name="helloWorld" class="demoStrutsStarter.HelloWorldAction">
<result name="input">/jsp/index.jsp</result>
<result>/jsp/helloWorld.jsp</result>
</action>
</package>
</struts>
But, I am getting a 404 error when I type:
http://localhost:8080/DemoStrutsStarter/index
I am not sure where I am wrong. Can anybody please help me find out why I am unable to call actions without .action extension?
Try adding a namespace to your package:
<package name="myPackage" namespace="/" extends="struts-default" >
Try this out in both results
result 1
<result>/WEB-INF/jsp/index.jsp</result>
result 2
<result>/WEB-INF/jsp/helloWorld.jsp</result>
else check your package name is correct or not.
by default, it's name default
try this links. it may help
1.stack overflow link 1
2.link 2 mkyong
3.stack overflow link 3
Related
Been banging my head for quiet sometime now as I don't seem to understand why struts is unable to find my action class.
This is my 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.mypackage.actions.TutotrialAction" method="execute">
<result name="success">/success.jsp</result>
<result name="failure">/error.jsp</result>
</action>
</package>
</struts>
This is my project structure
And finally this is the error that I see
Clearly the action seem to be present, not sure why it is unable to find it. Another eye ball would be appreciated!
Small typo:
<action name="getTutorial" class="org.mypackage.actions.TutotrialAction" method="execute">
^
should be
<action name="getTutorial" class="org.mypackage.actions.TutorialAction" method="execute">
With some help of the people here, I've managed to get my project to call the default actions of the packages without the suffix .htm. However, the request end up to index.jsp inside the webapp folder if I call the URL without the forward slash.
<struts>
<constant name="struts.enable.DynamicMethodInvocation" value="false"/>
<constant name="struts.action.extension" value="htm,," />
<constant name="struts.objectFactory" value="spring" />
<constant name="struts.devMode" value="true"/>
...
<package name="home" namespace="/secured" extends="default">
<default-action-ref name="index" />
<action name="index" class="homeAction" method="execute">
<result name="success" type="tiles">home</result>
</action>
</package>
</struts>
Actions are executed if I call http://someurl/someproject/secured/, but calling the URL http://someurl/someproject/secured end up to the file index.jsp.
What to do? Thanks
When you are calling http://someurl/someproject/secured url the secured is treated like action w/o suffix, because you have configured that actions can have empty suffix (which is also default btw). If you want that this url redirects to /secured namespace you can declare secured action with redirectAction result in package with empty or / namespace.
<package name="..." namespace="/" extends="struts-default">
...
<action name="secured">
<result type="redirectAction">
<param name="actionName">index</param>
<param name="namespace">/secured</param>
</result>
</action>
...
</package>
I have some own extended checks. I have exported them as plug-in and in Eclipse, they are showing warning/error. So the extended checks are working fine.
Now I want to generate a report of the violations in HTML format.
I have checked this, and this works fine if no extended checks are included in rule.xml file. But in case of extended checks, the ant build is giving the error.
The error is:
BUILD FAILED
D:\Java_Work\JUnit_CheckStyle\buildCheckStyle.xml:12: Unable to create a Checker: cannot initialize module TreeWalker - Unable to instantiate InterfaceModifier
InterfaceModifier is my extended check, and it works fine in eclipse.
In build.xml, where to provide the extendedCheck.jar so that I get the required result?
I have found out the following solution, which is working fine.
extract checkstyle-x.x-all.jar
copy the extended classes in the extracted directory
copy the metadata,message and properties file of extended check in the same directory.
if any of the file is alreasy present, then edit the file and add the content from extended checks.
create a new .jar file including all these.
in ant build.xml <taskdef>, set this .jar as classpath
Like, after done till 2nd step, I found checkstyle_packages.xml is already present, so I edit it and added the content from extended one in proper position.
Previous Version:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE checkstyle-packages PUBLIC
"-//Puppy Crawl//DTD Package Names 1.0//EN"
"http://www.puppycrawl.com/dtds/packages_1_0.dtd">
<checkstyle-packages>
<package name="com.puppycrawl.tools.checkstyle">
<package name="checks">
<package name="annotation"/>
<package name="blocks"/>
<package name="coding"/>
<package name="design"/>
<package name="duplicates"/>
<package name="header"/>
<package name="imports"/>
<package name="indentation"/>
<package name="javadoc"/>
<package name="metrics"/>
<package name="modifier"/>
<package name="naming"/>
<package name="regexp"/>
<package name="sizes"/>
<package name="whitespace"/>
</package>
<package name="filters"/>
</package>
</checkstyle-packages>
Changed Version:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE checkstyle-packages PUBLIC
"-//Puppy Crawl//DTD Package Names 1.0//EN"
"http://www.puppycrawl.com/dtds/packages_1_0.dtd">
<checkstyle-packages>
<package name="com.puppycrawl.tools.checkstyle">
<package name="checks">
<package name="annotation"/>
<package name="blocks"/>
<package name="coding"/>
<package name="design"/>
<package name="duplicates"/>
<package name="header"/>
<package name="imports"/>
<package name="indentation"/>
<package name="javadoc"/>
<package name="metrics"/>
<package name="modifier"/>
<package name="naming"/>
<package name="regexp"/>
<package name="sizes"/>
<package name="whitespace"/>
</package>
<package name="filters"/>
</package>
<!-- Added this lines -->
<package name="myCheck">
<package name="checks"/>
</package>
<!-- -->
</checkstyle-packages>
now the build file is running successfully and in the report I'm getting violation of extended checks too.
I have designed an application using struts2, and need to remove the extensions for example
www.myweb.com/register.action
How to remove the .action so when I click on register it call www.myweb.com/register without action extension?
I use the following
Register
I've found the answer. I should change the struts configuration as following:
<struts>
<constant name="struts.action.extension" value=""/>
<package name="default" extends="struts-default">
<action name="register">
<result type="tiles">register</result>
</action>
</package>
</struts>
If i try to use this action (test2) it always returns "The requested resource (/WebApplication4/newFolder/test2.jsp) is not available."
Running tomcat6 and netbeans 6.7.1
config.xml (it is included in 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="mypackage" namespace="/" extends="struts-default">
<action name="test2">
<result>/newFolder/test2.jsp</result>
</action>
</package>
</struts>
alt text http://img2.pict.com/87/b7/dc/1676731/0/clipboard4.jpg
but if i change result value from "/newFolder/test2.jsp" to "test.jsp" - everything works.
Solved, needed:
<result>/WEB-INF/newFolder/test2.jsp</result>