21:42
Sample Struts2.x Program:-
[a]- Create Dynamic Project in Your Eclipse IDE.
[b]- Add Some minimum set of library in WebContent\WEB-INF\lib folder and also put it into build-path whatever above mentioned.You can download
Create Sample Program
1-Create index.jsp
2-Create web.xml as deployment discriptor:-
3-Create Action Class as given below:-
Struts_Sample.java
4-Now Create struts.xml as given below:-
struts.xml
5-Create success.jsp as given below:-
success.jsp
Note :- You can create it in both either in src\struts.xml folder or WebContent\WEB-INF\classes\struts.xml like you can see in the given image below:-
Note :-
When I use eclipse to develop struts2. I found the struts.xml file can be put in src folder or WebContent\WEB-INF\classes. Both paths are ok.
What's the difference? what's better? Does different path affect the performance or other thing? Is there any other path for struts.xml file?
And the web.xml only can be put in WebContent\WEB-INF ?Or any other path for web.xml?
Explanation:-
1- From the web app's standpoint, there's no difference: struts.xml is expected to be at the root of the classpath after deployment. How and when it gets there is irrelevant.
2- Putting the config file in the source directory is better, because you shouldn't need to manage the class directory itself. Tools like Maven move artifacts from a project's src/main/resources directory to the classpath. It won't move an XML file from src/main/java unless specifically configured to do so.
3- No.
4- You may override the default location. There's rarely a good reason to; so don't. If you're using multiple config files it's fine to put them in packages, but I'd leave them on the classpath.
5- That's a totally unrelated question, but it should stay in the default location, WEB-INF. WebContent is project-specific (Eclipse)–you'd need to configure the deployment/packaging process to find it.
Multiple Configuration File(struts.xml)
For a large application, it is better to use multiple configuration file that one so that it may be easy to manage the application.
We can create many configuration files but we need to define it in the struts.xml file. The includesub-element of struts is used to define the supported configuration file.
Example :-
1- Create index.jsp
2- Create struts.xml:-
3- Create WEB-INF/classes/first/struts-first.xml
and
WEB-INF/classes/second/struts_second.xml:-
[a]- Create WEB-INF/classes/first/struts-first.xml:-
[b]- Create WEB-INF/classes/second/struts_second.xml:-
4- Create Action Class For this struts-first.xml And struts_second.xml:-
[a]- Create Action Class For this struts-first.xml:-
Struts_Sample1.java:-
[b]- Create Action Class For this struts_second.xml:-
Struts_Sample2.java:-
5- Create welcome.jsp:-
6- Create error.jsp:-
0 comments:
Post a Comment