servlet的init(ServletConfig config)方法中会有一个super.init(config);其原理如下:
1.如果用户不需要设置一些初始化操作,那么init()方法的实现可有可无,因为可以从父类GenericServlet中继承得到.
2.如果用户需要servlet通过<init-param>从web.xml中读取initialization parameters或者configuration data,那么就需要显式实现init()方法.
3.GenericServlet 提供两个overloaded形式的方法如下:
public void init() throws ServletException
public void init(ServletConfig) throws ServletException
4.Servlet interface只定义一个init(ServletConfig)方法,而且servlet加载时必须被调用,但只在第一次加载被调用一次.
5.GenericServlet实现了这个init(ServletConfig)方法,这个方法先保存ServletConfig reference,然后调用init()方法.
6.如果用户servlet实现init()方法并在其中填充自己需要初始化的信息,这个init()会被GenericServlet中的init(ServletConfig)方法调用.因为ServletConfig reference已经
被保存,所以你可以访问web.xml中的<init-param>.
7.如果用户servlet实现init(ServletConfig),那么就覆盖了GenericServlet(父类)的init(ServletConfig)方法,因此,GenericServlet会调用子类的方法,而不会保存
ServletConfig reference,必须执行super.init(config);才能保存ServletConfig reference访问web.xml中的<init-param>.
8.所以你有两种方法初始化,如下:
第一种方法是
public class LoginServlet extends HttpServlet {
public void init() throws ServletException {
}
//...Rest of Servlet
}
第二中方法是
public class LoginServlet extends HttpServlet {
public void init(ServletConfig config) throws ServletException {
super.init(config);
// ...Remainder of init() method
}
//...Rest of Servlet
}
9.servlet初始化正常结束,才能处理处理用户的请求,如果在初始化方法init()中出现错误,那么需要throw a ServletException或者父类的UnavailableException.这会告诉
servlet容器初始化失败,不能处理任何请求.
10.在GenericServlet中,init(ServletConfig)先被调用,主要是用于保存ServletConfig reference,然后调用init(),因此这时候init()可以用于加载在web.xml里配置的<init-param>的初始化参数, 在web.xml中设置初始化参数如下
<servlet>
<servlet-name>rbacAction</servlet-name>
<servlet-class>
cdc.dm.servlet.BaseServlet
</servlet-class>
<init-param>
<param-name>service-class</param-name>
<param-value>
cdc.dm.action.rbac.impl.RbacActionImpl
</param-value>
</init-param>
</servlet>
11.在HttpServlet中如果覆盖init()不会影响init(ServletConfig)对ServletConfig reference的保存,所以这种情况下在init()中可以获取初始化参数
12.在HttpServlet中如果覆盖init(ServletConfig),则ServletConfig reference就不会被保存,所以这是时候当init(ServletConfig)运行完后再调用init()时,init()就找不到ServletConfig reference了。所以为了能够在init()中获取初始化参数,应该在覆盖init(ServletConfig)时首先要调用super.init(config)也就是GenericServlet的init(ServletConfig)来保存ServletConfig reference
分享到:
相关推荐
super(); this.stage.scaleMode = flash.display.StageScaleMode.NO_SCALE; this.stage.align = flash.display.StageAlign.TOP_LEFT; configURL = "settings.xml"; if (this.root.loaderInfo.parameters.config...
.....\.......\.....\config.h .....\.......\.....\fs.h .....\.......\.....\hdreg.h .....\.......\.....\head.h .....\.......\.....\kernel.h .....\.......\.....\mm.h .....\.......\.....\sched.h ....
项目简介: 使用YOLOv5+Deepsort实现车辆行人追踪和计数,代码封装成一个Detector类,更容易嵌入... super(Detector, self).__init__() self.init_model() self.build_config() def init_model(self): self.weig
mBitmap = Bitmap.createBitmap(mBitmapWidth, mBitmapHeight, Bitmap.Config.RGB_565); mCanvas = new Canvas(mBitmap); mPaint.setStyle(Paint.Style.STROKE); mPaint.setStrokeCap(Paint.Cap.ROUND); ...
新节点 整合状态 安卓 添加到您的build.gradle中: ... 添加到您的应用程序或活动中: ...config.connectionProxyDictionary = NewNode.connectionProxyDictionary; NSURLSession *session = [ NSURLSes
super.onCreate(savedInstanceState); setContentView(R.layout.main); init(); } private void init() { /* 配置config * 参数1:数组第一维的长度 * 参数2:数组第二维的长度 * 参数3:第一张...
记录仪 日志记录器是一种日志记录工具,可以帮助统一发布日志和调试日志,并且具有一些高级用法。... super . onCreate(); if ( BuildConfig . DEBUG ) { Logger . init( this , ReleaseLogger . getInstance());
nested exception is org.springframework.core.NestedIOException: Failed to parse config resource: class path resource [mybatis- config.xml]; nested exception is org.apache.ibatis.builder....
本文地址: ://blog.csdn.net/weixin_44936889/article/details/112002152 ... super ( Detector , self ). __init__ () self . init_model () self . build_config () def init_model ( self ):
startGame(config.ENDTIME); } }); sucessDialog=new AlertDialog.Builder(this); sucessDialog.setTitle("Sucess"); sucessDialog.setMessage("游戏成功了"); sucessDialog.setIcon(R.drawable....
.setBitmapConfig(Bitmap.Config.ARGB_8888) // 设置图片位图模式(默认是Bitmap.CacheConfig.ARGB_8888) .setMemoryCachelimit(Runtime.getRuntime().maxMemory() / 3) // 设置图片内存缓存大小(默认是...
FRAG_PROCESSED:"hlsSubtitleFragProcessed",CUES_PARSED:"hlsCuesParsed",NON_NATIVE_TEXT_TRACKS_FOUND:"hlsNonNativeTextTracksFound",INIT_PTS_FOUND:"hlsInitPtsFound",FRAG_LOADING:"hlsFragLoading",FRAG_...
R:\wyb\ap6212a0_a33_sc3817r\android\device\softwinner\astar-y3\overlay\frameworks\base\core\res\res\values\config.xml <!-- List of regexpressions describing the interface (if any) that represent ...
R:\wyb\ap6212a0_a33_sc3817r\android\device\softwinner\astar-y3\overlay\frameworks\base\core\res\res\values\config.xml <!-- List of regexpressions describing the interface (if any) that represent ...
self.classifier = nn.Linear(config.hidden_size, num_labels) 替换为: self.classifier = MLP(config.hidden_size, num_labels) 并且添加MLP模块: class MLP(nn.Module): def __init__(self, input_size, ...
Overview Package Class Tree Deprecated Index Help PREV NEXT FRAMES NO FRAMES A B C D E F G H I J L P R S U V -------------------------------------------------------------------------------- ...
super.onConfigurationChanged(newConfig); // 检测屏幕的方向:纵向或横向 if (this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { // 当前为横屏, 在此处添加...
│ │ config.h │ │ fs.h │ │ hdreg.h │ │ head.h │ │ kernel.h │ │ mm.h │ │ sched.h │ │ sys.h │ │ tty.h │ │ │ └─sys │ stat.h │ times.h │ types.h │ utsname.h │ wait.h │ ├─init...
数字音频工作站关于见。安装在您的服务器公共目录中...define('plugins/my_cool_plugin', ['Gadget'], function(Gadget) { var MyCoolPlugin = Gadget.extend({ // constructor init: function() { this._super(); this
BlazeDS 将读取 services-config.xml 配置文件,该配置文件又引用了 remoting-config.xml、proxy-config.xml 和 messaging-config.xml 这 3 个配置文件,所以,一共需要 4 个配置文件。 由于 BlazeDS 需要将 Java ...