eclipse not validating the struts.xml file - java

I installed the eclipse in my new p.c. and import my old project of struts2 in that and after importing the project i got a warning in struts.xml file i.e. "The file cannot be validated as there was a connection problem.". I replaced my jar files and doctype so many times but still it didn't work. I also found that eclipse is not showing me any error if i do something wrong in that file even when eclipse clean my project it takes a lot of time to clean struts.xml file
<?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>
<package name="a" extends="struts-default">
<action name="b" class="com.test">
<result name="success">/success.jsp</result>
<result name="error">/error.jsp</result>
</action>
</package>
</struts>
Please help me for this i am getting lots of difficulties...???

Change Doctype to:
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.1//EN"
"/WEB-INF/dtds/struts-2.1.dtd">
and extract "struts-2.1.dtd" file from "struts2-core-2.1.8.1.jar" into dtds folder(CREATE NEW) inside WEB-INF folder.

This happens when eclipse could not open the file, this happens sometimes for me when I have internet connection problems.
So make sure you have internet connection and you have not set any proxy which is not working and prevent eclipse to access the internet. You can open struts.xml and ctl+click on http://struts.apache.org/dtds/struts-2.3.dtd
If your problem is not solved, you can do as mentioned by #AsSide, copy the struts-2.3.dtd some where in your hard and change the struts.xml as below:
<!DOCTYPE struts SYSTEM "c://struts-2.3.dtd">
The DOCTYPE must be changed to SYSTEM instead of PUBLIC. Change the dtd location is not a good approach :)

Related

struts.convention.result.path is not working in Struts2

My current project structure is as follows
WebContent
WEB-INF
View
TestPage.jsp
other JSP pages...
My assignment is to put all JSP pages inside folder WEB-INF and do all relative changes in the project.
WebContent
WEB-INF
View
TestPage.jsp
other JSP pages...
So I have to update all result tag in struts.xml
<result name="success">/View/TestPage.jsp</result>
to
<result name="success">/WEB_INF/View/TestPage.jsp</result>
After search on web I found a plugin - struts convention plugin to achieve this, But it follows its Naming convention.
Can I override Struts convention plugin configuration (that will not follow its naming convention)?I have tried too, but it is not reflecting. My struts.xml is
<struts>
<constant name="struts.devMoade" value="true" />
<constant name="struts.convention.result.path" value="/WEB-INF/View/" />
<package name="test" extends="struts-default" namespace="/">
<action name="hello1" class="testAction.Hello1Action">
<result name="success">/TestPage.jsp</result>
</action>
</package>
</struts>
When I run
localhost:8080/project-name/hello1
It displays error 404.But if I change result in struts.xml as
<result name="success">/WEB-INF/View/TestPage.jsp</result>
It works fine.
I don't wanna do changes in all result tags.How can I achieve this by doing changes at one place?
The convention plugin uses a different configuration provider and this constant only works with configuration created by convention.
<constant name="struts.convention.result.path" value="/WEB-INF/View/" />
If you want to override the convention configuration you should use annotations.
package testAction;
#ParentPackage("json-default")
#Namespace("/")
#Action(value="hello1", results=#Result(name = "success", location="TestPage.jsp"))
public class Hello1Action extends ActionSupport {
}

Struts2: Setting constant struts.action.extension to "," not working

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

Generating Checkstyle Reports (with extended checks)

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.

Struts 2 action class not working

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

Resource ... is not available

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>

Categories

Resources