Myeclippse using interceptors defined in Struts-default.xml (Timmer,logger)

Source: Internet
Author: User

Environment: MyEclipse Stable 2.0;struts2-core-2.3.16.1.jar, etc.

Struts.xml

<Struts>                    < Packagename= "P1"namespace="/"extends= "Struts-default">                    <Actionname= "M1"class= "Org.ah.s2.C1"Method= "M1">        <interceptor-ref name= "Timer"/> <interceptor-ref name= " logger"/>                               <resultname= "Success"type= "Dispatcher">/success.jsp</result>            </Action>            </ Package>            </Struts>                

Some people say it is necessary to add <interceptor-ref name= "Defaultstack"/>, which is actually caused by superficial understanding.

However, MyEclipse, log does not output, need to configure log4j.properties, placed under SRC

#
# log4j Settings for log4j 1.2.x (via jakarta-commons-logging)
#
# The five logging levels used by Log is (in order):
#
# 1. DEBUG (the least serious)
# 2. INFO
# 3. WARN
# 4. ERROR
# 5. FATAL (the most serious)


# Set Root logger level to WARN and append to stdout
Log4j.rootlogger=info, stdout
Log4j.appender.stdout=org.apache.log4j.consoleappender
Log4j.appender.stdout.target=system.out
Log4j.appender.stdout.layout=org.apache.log4j.patternlayout

# Pattern to output the caller's file name and line number.
log4j.appender.stdout.layout.conversionpattern=%d%5p (%c:%l)-%m%n

# Print only messages of level ERROR or above in the package nomodule.
Log4j.logger.nomodule=fatal

# Opensymphony Stuff
Log4j.logger.com.opensymphony=info
Log4j.logger.org.apache.struts2=info

# Spring Stuff
Log4j.logger.org.springframework=info

The log level for Timmer and logger is info, and the level is set to info.

Other auxiliary files:

  index.jsp         <s:form action= "M1" method= "POST" >            <s:submit value= "test struts Control Pass value" ></s:submit>    </s: form>                Action:        package  org.ah.s2;                 Import Com.opensymphony.xwork2.ActionSupport;                  Public class extends Actionsupport {            public  String M1 () {                    return "Success";    }    }        

Test it:

2016-12-31 21:51:00,312 INFO (com.opensymphony.xwork2.interceptor.logginginterceptor:42)-Starting execution stack For Action//m1
2016-12-31 21:51:00,354 INFO (com.opensymphony.xwork2.interceptor.logginginterceptor:42)-Finishing execution stack For Action//m1
2016-12-31 21:51:00,354 INFO (com.opensymphony.xwork2.interceptor.timerinterceptor:42)-Executed action [//M1!M1] Took Ms.

Myeclippse using interceptors defined in Struts-default.xml (Timmer,logger)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.