In a Struts 2 based project, one of the jar files i am using is struts2-core-2.0.14.jar, and when i removed this jar and replaced this with struts2-core-2.1.8.1.jar the application fails to start.
Most Probable, as far as i understand, the problem is with the filter class declared in web.xml
For the version of struts2.0.x,The class "org.apache.struts2.dispatcher.FilterDispatcher" is used as filter.
For the version of struts2.1.x,The class "org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter" is used as filter.
For more inform, please refer
http://www.mkyong.com/struts2/difference-between-struts-2-filterdispatcher-and-strutsprepareandexecutefilter/
Related
I'am new to grails, I wanted to make use of Dynamic Controller Plugin (http://grails.org/plugin/dynamic-controller) in my project.
I am using grails version 3.2.11
I've added the dependency as directed on the page. It downloads the dependency in the form of zip, I can see it in External libraries. But when I am trying to import two classes (as directed on http://burtbeckwith.com/blog/?p=1041 Linking to existing Controller Actions
approach)
import com.burtbeckwith.grails.plugins.dynamiccontroller.ControllerClosureSource
import com.burtbeckwith.grails.plugins.dynamiccontroller.DynamicControllerManager
it gives " unable to resolve class" error. Please suggest what am I doing wrong here. Thanks!
You're trying to install a Grails 2 plugin in a Grails 3+ app, but that's not possible since they're not compatible. Grails 2 plugins must be upgraded and reworked to be used in Grails 3, and there's no plan to do so for this plugin.
I would say take a look at the URL Mappings & Embedded variables in the grails documentation.
https://docs.grails.org/3.2.11/guide/single.html#embeddedVariables
For example:
static mappings = {
"/blog/$topic"(controller: "blog")
}
which gives you a feeling like you are dynamically declaring actions.
And the topic variable is accessible through GrailsParameterMap params object # controller.
With this you can construct url like:
www.mysite.com/blog/football
www.mysite.com/blog/tvshow
www.mysite.com/blog/etc
Edit: you can also take a look at Dynamic Controller and Action Names [https://docs.grails.org/3.2.11/guide/single.html#_dynamic_controller_and_action_names]
I am new to struts so this could be a basic concept I am facing problem with.
I have a code which access the ID of util:copyTag inside scriptlet:
<%# taglib uri="/WEB-INF/tlds/copytag.tld" prefix="util" %>
...
...
<util:copyTag id="tablebuffer" >
....
</util:copyTag>
<%
Hashtable h=new Hashtable();
String Key = "key1";
h.put(Key,tablebuffer);
%>
When using this code in eclipse, line h.put(Key,tablebuffer); gives a red marker with popup text:
Multiple annotations found at this line:
- tablebuffer cannot be resolved to a
variable
- tablebuffer cannot be resolved to a
variable
Is it possible to use the ID as a variable, or is there some other way to do this. Actually I was given this code and told that code works fine. However when I configured the code in Eclipse I am facing the mentioned issue.
Kindly help me with this issue.
The only possible answer is:
Never use Scriptlets anymore: they're a bad practice.
Never use Struts1 anymore: it is EOL.
Apache Struts 1 End-Of-Life (EOL) Announcement
The Apache Struts Project Team would like to inform you that the Struts 1.x web framework has reached its end of life and is no longer officially supported.
[...]
We plan to start a new project based on Struts 1. Can we still do so?
Basically yes, but we would not recommend doing so. As long as no code line is written it is very easy to conceptually select an alternative web framework such as Struts 2.
Also, Struts 2 is easier and more powerful... really, if you are starting something new (and not maintaining a huge S1 project), switch to it, or to the alternatives (JSF 2, Spring MVC, and so on)
I am using JSR 303 Bean validation in my JSF 2.0 web application and it works fine with annotations. Now I would like to ignore annotations and configure validation rules using the validation.xml file, so this is what I did (I am using an eclipse dynamic web project) :
Added validation.xml under WebContent/META-INF/validation.xml
<?xml version="1.0" encoding="UTF-8"?>
<validation-config
xmlns="http://jboss.org/xml/ns/javax/validation/configuration"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://jboss.org/xml/ns/javax/validation/configuration validation-configuration-1.0.xsd"
>
<constraint-mapping>META-INF/validation/constraint-mapping.xml</constraint-mapping>
</validation-config>
Then created the file constraint-mapping.xml under WebContent/META-INF/validation/constraint-mapping.xml
<constraint-mappings xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://jboss.org/xml/ns/javax/validation/mapping validation-mapping-1.0.xsd"
xmlns="http://jboss.org/xml/ns/javax/validation/mapping">
<bean class="my.full.path.ValidationMB" ignore-annotations="true">
</bean>
</constraint-mappings>
Having these configurations in place, I suppose the annotations in my bean class ValidationMB shall be ignored, BUT this is not happening!, which makes me assume that the validation.xml file is not being loaded.
any ideas? thanks.
Environment:
Apache Tomcat 7.0.23
javax.faces-2.1.4.jar
hibernate-validator-4.2.0.Final.jar
hibernate-validator-annotation-processor-4.2.0.Final.jar
validation-api-1.0.0.GA.jar
slf4j-api-1.6.1.jar
From the spec: section 4.4.6. XML Configuration: META-INF/validation.xml
Unless explicitly ignored by calling
Configuration.ignoreXMLConfiguration(), a Configuration takes into
account the configuration available in META-INF/validation.xml. This
configuration file is optional but can be used by applications to
refine some of the Bean Validation behavior. If more than one
META-INF/validation.xml file is found in the classpath, a
ValidationException is raised.
To solve my problem I had to create a META-INF folder under the project src folder, which ends in the WEB-INF/classes/META-INF.
The structure of the web application is:
ROOT
|_META-INF -- don't put validation.xml here
|_WEB-INF
|__ classes
|_META-INF
|__validation.xml
But I think that if I pack my web application in a jar file and reuse it in another project It may not work, I will let you know later once I do it.
Try to put your validation.xml directly into the WEB-INF/ directory.
I stumbled across this while looking for something else but wanted to clarify to the OP what is happening. You do in fact need the file to exist at META-INF/validation.xml; however, that is relative to the classpath which is why it worked when you put it under WEB-INF/classes/META-INF/validation.xml.
The cleaner approach is to let the file be put there for you. Your Eclipse project should already be outputting whatever is in your source directory to WEB-INF/classes somehow for you or nothing would be running. But sometimes there are filters on what it outputs so it might excluding something. You might want to check your src dirs and make sure they don't have exclusions.
Just as an example, if you had a Maven war project, all of your java sources would go in src/main/java and the generated classes would end up in the WEB-INF/classes directory. The equivalent happens for src/main/resources which contains non-source files. When I want *.xml, *.properties, etc. to end up in WEB-INF/classes I put them in src/main/resources. For your example I would have a src/main/resources/META-INF/validation.xml file.
Hope this helps anyone else who comes across this and is confused.
I created a custom attribute called "CoverageExcludeAttribute", and placed it above the classes which I want to exclude from my code coverage analysis. But the exclusions doesn't work. The coverage report shows coverage for the Test dll along with all the referenced assemblies (which includes classes containing the exclusion attribute)
<UsingTask TaskName="NCoverExplorer.MSBuildTasks.NCover" AssemblyFile="$(Libraries)\NCoverExplorer.MSBuildTasks.dll"/>
<Target Name="NcoverCoverage">
<NCover ToolPath="C:\Program Files\TestDriven.NET 3\NCover\1.5.8"
CommandLineExe="D:\Xunit\xunit.console.exe"
CommandLineArgs="MyTestDll"
WorkingDirectory="MyWorkingDirectory"
excludeAttributes="CoverageExcludeAttribute"
LogFile="coverage.log"
/>
</Target>
Am I missing something?
Thanks.
Make sure that your attribute is defined in a global namespace or provide a full type name in excludeAttributes.
If you are using .NET Framework 4.0 you can use existing attribute
ExcludeFromCodeCoverageAttribute
From namespace:
System.Diagnostic.CodeAnalysis
That seems to be working fine for me when using NCover 1.5.8 at least when using NCoverExplorer. This attribute is picked up automatically.
With Struts2 we have to have struts.xml in the class path, so it no longer works to have it under WEB-INF. So the way I got my project to deploy was to stick it under WEB-INF/classes and have it include ../struts2.xml
2 Problems:
Eclipse cleans out the classes folder when I do a rebuild, so it
deletes struts.xml
Eclipse doesn't show the classes folder in my project browser, so
its a poor place to stick config files in the first place.
How are you Struts2 Eclipse developers doing this?
You can either just put the struts.xml at the root of your source directory or set up an additional resources source directory and put it there. Eclipse quite happily copies it to WEB-INF/classes for you when it does a compilation.
I am late to the party, we can configure the struts.xml in any directory in the classpath of the web application, but provide the location using the "config" init parameter of the filter configuration in web.xml as below, if my struts.xml file is in "/com/resources/" directory.
<filter>
<filter-name>action</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
<init-param>
<param-name>config</param-name>
<param-value>struts-default.xml,struts-plugin.xml,/com/resources/struts.xml</param-value>
</init-param>
</filter>
If we don't provide a config init parameter struts2 by default takes 3 values "struts-default.xml,struts-plugin.xml,struts.xml", you can see the struts2 Dispatcher class code below which will configure these 3 files to the configuration manager.
String configPaths = (String)this.initParams.get("config");
if (configPaths == null) {
configPaths = "struts-default.xml,struts-plugin.xml,struts.xml";
}
String[] files = configPaths.split("\\s*[,]\\s*");
for (String file : files)
if (file.endsWith(".xml")) {
if ("xwork.xml".equals(file))
this.configurationManager.addContainerProvider(createXmlConfigurationProvider(file, false));
else
this.configurationManager.addContainerProvider(createStrutsXmlConfigurationProvider(file, false, this.servletContext));
}
With Struts 1.2, it was required to put the struts-config.xml in the classpath (under WEB-INF folder) but with Struts 2.0, it is required to be in src/main/resources folder.
See the documentation Struts 2 Documentation here
I pasted struts.xml in this directory and the project executed fine.
I am not using Eclipse so this answer is not specific to your requirements but, I use Maven so we have all the "resources" that are needed by the application in a seperate folder called "resources" and When the application is built these files are copied into the appropriate places automatically. In Netbeans the files in the folder are available and I know that there are persons using eclipse with a similar setup.
I should point out that our project started from appfuse so most of these configurations were pre made. You can look at how it was done there.
In struts 2 projects, struts.xml file is added in src(Java Resources) folder along with the packages and libraries.
Please refer the image given below.
If u want to know more about struts 2 project structure please visit this link
Note: In eclipse, you are not allowed to paste a file directly in src folder. So you need to first paste it in any other place in the project( for example, in 'WebContent' folder), then use move functionality to put it in right place( That is 'src' folder).
You can place struts.xml file in src(Java Resources) packages.
When the compilation process struts.xml file will generate inside the ROOT/WEB-INF/classes directory.
if you get the same error again and again better check the struts actions.
check the deployed path of the application and you can find out what you want.
(struts.xml file)