首先我们来看下struts2的执行过程

struts2执行过程.jpg

如果各位有兴趣的话可以去查看下Struts2的源码,这里我只贴出 StrutsPrepareAndExecuteFilter 这个过滤器在中的inti方法

public class StrutsPrepareAndExecuteFilter implements StrutsStatics, Filter {
    protected PrepareOperations prepare;
    protected ExecuteOperations execute;
    protected List<Pattern> excludedPatterns = null;

    public void init(FilterConfig filterConfig) throws ServletException {
        InitOperations init = new InitOperations();
        Dispatcher dispatcher = null;
        try {
            FilterHostConfig config = new FilterHostConfig(filterConfig);
            init.initLogging(config);
            dispatcher = init.initDispatcher(config);
            init.initStaticContentLoader(config, dispatcher);

            prepare = new PrepareOperations(dispatcher);
            execute = new ExecuteOperations(dispatcher);
            this.excludedPatterns = init.buildExcludedPatternsList(dispatcher);

            postInit(dispatcher, filterConfig);
        } finally {
            if (dispatcher != null) {
                dispatcher.cleanUpAfterInit();
            }
            init.cleanup();
        }
    }

根据代码实现过滤器在服务器启动的时候创建,创建过滤器的时候执行init方法,在init方法中主要加载配置文件,包含自己创建的配置文件和struts2自带配置文件struts.xml 

        Struts2配置详解

       1、 struts2的核心配置文件的名称和位置是固定的,位置只能存放在src下面,名称固定为struts.xml。

image.png

1、struts.xml文件内容

<?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="default" namespace="/" extends="struts-default">
 
    <action name="userAction" class="com.netxintai.action.UserAction">
    
    	<result name="login">/index.jsp</result>
    
    </action>
    
    </package>

</struts>

   配置文件中主要有三个标签分别是: package、action和result

  标签 package

    1、类似于代码包,区别不同的action 要配置action 首先写pagckage标签,在package里面才能配置action

    2、package标签属性

         一、name属性:一个配置文件可以写多个package标签,name属性用于区分不同的package,每个name属性值不能相同

         二、extends属性:属性值固定为 struts-default 有了这个属性之后,在package里面配置的类具有action功能  extends="struts-default"

         三、namespace属性:与action标签里面的name属性值构成访问路径  namespace="/"

   action标签

      1 name属性 :一、namespace属性值和action和标签里面的name属性值构成访问路径 例如http://localhost:8080/day01/userAction 红色字                                      体部分就是package中的nameespace="/"和action标签中的name="userAction"构成的

                             二、在package标签里面可以写多个action标签,但是action的name属性值不能相同

      2 class 属性 :Action的全路径; class="com.netxintai.action.UserAction"

      3 method属性 : 让一个action可以执行多个方法。method="{1}"   

   result 标签  根据action中方法的返回值,配置到不同的路径里面

       1 name属性:必须和方法返回值一样,否则无法找到路径

       2 type属性:配置为转发或者重定向属性 默认是转发操作

        

72 Thoughts on “struts2教程-配置文件详解

  1. hey there and thank you for your info – I’ve definitely picked up
    something new from right here. I did however expertise a few technical points using
    this web site, since I experienced to reload the website a lot of times previous to I could
    get it to load correctly. I had been wondering if
    your web hosting is OK? Not that I’m complaining, but sluggish loading instances times will very frequently
    affect your placement in google and could damage your quality score if advertising
    and marketing with Adwords. Well I am adding this RSS to my email and
    could look out for a lot more of your respective
    exciting content. Make sure you update this again very soon..

    Lista escape room

  2. Very interesting information!Perfect just what I was looking for!!

  3. bookmarked!!, I really like your web site.

  4. A fascinating discussion is worth comment. I do think that you need to write more on this subject, it might not be a taboo matter but generally folks don’t talk about such topics. To the next! Many thanks.

  5. This is a topic which is near to my heart… Cheers! Exactly where are your contact details though?

  6. Excellent blog post. I definitely appreciate this website. Continue the good work!

  7. Good blog post. I certainly love this website. Continue the good work!

  8. I truly love your website.. Very nice colors & theme. Did you create this web site yourself? Please reply back as I’m trying to create my very own site and would love to find out where you got this from or just what the theme is called. Kudos!

  9. I quite like looking through an article that will make people think. Also, thanks for allowing for me to comment.

  10. bookmarked!!, I love your site!

  11. Very nice write-up. I absolutely appreciate this site. Keep it up!

  12. I’m very pleased to uncover this web site. I need to to thank you for ones time for this wonderful read!! I definitely savored every little bit of it and i also have you book-marked to check out new information in your web site.

  13. I was able to find good advice from your articles.

  14. Pretty! This has been a really wonderful post. Many thanks for providing this info.

  15. I’m amazed, I have to admit. Rarely do I encounter a blog that’s both equally educative and entertaining, and without a doubt, you’ve hit the nail on the head. The issue is an issue that too few people are speaking intelligently about. I’m very happy that I stumbled across this in my search for something regarding this.

  16. I’m amazed, I must say. Rarely do I come across a blog that’s both equally educative and entertaining, and without a doubt, you’ve hit the nail on the head. The problem is something too few people are speaking intelligently about. Now i’m very happy I found this in my hunt for something regarding this.

  17. This site was… how do I say it? Relevant!! Finally I’ve found something that helped me. Many thanks.

  18. Hi there! This post couldn’t be written any better! Reading through this post reminds me of my previous roommate! He continually kept preaching about this. I am going to send this information to him. Fairly certain he’s going to have a great read. I appreciate you for sharing!

  19. I used to be able to find good information from your blog articles.

  20. I could not refrain from commenting. Exceptionally well written.

  21. Nice post. I learn something totally new and challenging on blogs I stumbleupon everyday. It will always be interesting to read through articles from other writers and practice a little something from their sites.

  22. After exploring a few of the blog articles on your web site, I really appreciate your technique of writing a blog. I book marked it to my bookmark webpage list and will be checking back in the near future. Please check out my web site as well and tell me what you think.

  23. I want to to thank you for this great read!! I certainly enjoyed every little bit of it. I have you bookmarked to look at new stuff you post…

  24. I could not refrain from commenting. Well written!

  25. It’s nearly impossible to find well-informed people about this topic, but you seem like you know what you’re talking about! Thanks

  26. You are so cool! I do not believe I have read through anything like that before. So wonderful to discover another person with a few genuine thoughts on this topic. Really.. thank you for starting this up. This website is something that’s needed on the internet, someone with some originality.

  27. You need to take part in a contest for one of the most useful blogs on the web. I will highly recommend this blog!

  28. When I originally left a comment I seem to have clicked on the -Notify me when new comments are added- checkbox and now whenever a comment is added I get 4 emails with the same comment. Is there a way you can remove me from that service? Thank you.

  29. I really like it when individuals get together and share thoughts. Great website, continue the good work.

  30. I blog often and I truly appreciate your content. The article has really peaked my interest. I’m going to book mark your blog and keep checking for new information about once per week. I opted in for your RSS feed too.

  31. I’m impressed, I have to admit. Seldom do I come across a blog that’s both educative and engaging, and let me tell you, you’ve hit the nail on the head. The problem is an issue that too few folks are speaking intelligently about. I am very happy I stumbled across this during my hunt for something relating to this.

  32. Saved as a favorite, I love your website.

  33. Great information. Lucky me I found your blog by chance (stumbleupon). I have book marked it for later.

  34. Greetings! Very useful advice within this article! It’s the little changes that will make the greatest changes. Many thanks for sharing!

  35. I’m impressed, I must say. Rarely do I come across a blog that’s both educative and entertaining, and let me tell you, you’ve hit the nail on the head. The issue is an issue that too few men and women are speaking intelligently about. I am very happy I came across this in my search for something concerning this.

  36. Can I simply just say what a comfort to discover an individual who truly knows what they are discussing on the web. You definitely know how to bring a problem to light and make it important. A lot more people really need to check this out and understand this side of your story. I was surprised you aren’t more popular because you definitely have the gift.

  37. This excellent website certainly has all the info I wanted about this subject and didn’t know who to ask.

  38. I could not refrain from commenting. Exceptionally well written!

  39. A fascinating discussion is definitely worth comment. I do think that you should publish more about this subject, it might not be a taboo matter but generally folks don’t discuss these topics. To the next! Kind regards.

  40. Howdy, There’s no doubt that your blog might be having web browser compatibility problems. When I look at your site in Safari, it looks fine but when opening in I.E., it’s got some overlapping issues. I merely wanted to provide you with a quick heads up! Other than that, excellent blog!

  41. Hi! I could have sworn I’ve visited this website before but after browsing through some of the posts I realized it’s new to me. Nonetheless, I’m certainly delighted I came across it and I’ll be book-marking it and checking back regularly.

  42. cialis and priligy Yusuf E, Kortekaas MC, Watt I, Huizinga TWJ, Kloppenburg M

  43. Hello there! Do you know if they make any plugins to help with Search Engine
    Optimization? I’m trying to get my website to rank for some targeted keywords but I’m not seeing very
    good gains. If you know of any please share. Kudos! I saw similar blog here:
    Eco product

  44. You have made some really good points there. I checked on the web for more info about the issue and found most people will go along with your views on this website.

  45. Your style is unique compared to other folks I’ve read stuff from. Thanks for posting when you’ve got the opportunity, Guess I’ll just bookmark this page.

  46. Hello there! I just wish to give you a huge thumbs up for the great info you’ve got here on this post. I am coming back to your site for more soon.

  47. Great post! We are linking to this great article on our site. Keep up the great writing.

  48. This blog has become a part of my daily routine I start my mornings with a cup of coffee and your latest post

  49. An impressive share! I’ve just forwarded this onto a coworker who was conducting a little homework on this. And he actually bought me breakfast due to the fact that I found it for him… lol. So let me reword this…. Thanks for the meal!! But yeah, thanx for spending the time to discuss this subject here on your site.

  50. Your blog post was really enjoyable to read, and I appreciate the effort you put into creating such great content. Keep up the great work!

  51. Your style is unique compared to other folks I have read stuff from. I appreciate you for posting when you have the opportunity, Guess I’ll just bookmark this site.

  52. Hi! I just want to give you a huge thumbs up for your great information you’ve got right here on this post. I will be returning to your website for more soon.

  53. Great post. I will be dealing with a few of these issues as well..

  54. Introducing to you the most prestigious online entertainment address today. Visit now to experience now!

  55. Hello! I simply wish to give you a huge thumbs up for your great information you’ve got here on this post. I am coming back to your web site for more soon.

  56. You need to take part in a contest for one of the most useful blogs online. I am going to recommend this web site!

  57. Your blog has quickly become one of my favorites I always look forward to your new posts and the insights they offer

  58. This is a good tip particularly to those fresh to the blogosphere. Short but very precise information… Thank you for sharing this one. A must read article!

  59. Your positivity and enthusiasm are contagious Reading your blog has become a part of my daily routine and I always leave feeling better than when I arrived

  60. Can I just say what a comfort to discover someone that genuinely knows what they’re discussing on the web. You definitely understand how to bring an issue to light and make it important. More people really need to look at this and understand this side of the story. I was surprised you are not more popular since you definitely have the gift.

  61. May I simply just say what a comfort to discover someone who actually knows what they’re talking about on the web. You definitely know how to bring a problem to light and make it important. More people should read this and understand this side of your story. I was surprised you are not more popular because you definitely have the gift.

  62. Introducing to you the most prestigious online entertainment address today. Visit now to experience now!

  63. Great post! We are linking to this particularly great article on our website. Keep up the great writing.

  64. mk sports hiếp dâm trẻ em

  65. mk sports Quay lén phụ nữ

  66. I’d like to thank you for the efforts you’ve put in writing this blog. I am hoping to see the same high-grade content by you later on as well. In fact, your creative writing abilities has motivated me to get my own blog now 😉

  67. I could not resist commenting. Very well written!

  68. This is a topic that’s close to my heart… Best wishes! Where are your contact details though?

  69. Amazing post! I’ll definitely be using this knowledge.

  70. Oh my goodness! Incredible article dude! Thanks, However I am having issues with your RSS. I don’t know the reason why I am unable to subscribe to it. Is there anybody else having the same RSS problems? Anybody who knows the solution will you kindly respond? Thanks!

  71. Spot on with this write-up, I truly believe that this web site needs far more attention. I’ll probably be back again to read through more, thanks for the advice!

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

Post Navigation