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)