怎样能让idea不能创建servlett成为默认首页

Servlet的init()方法如何才会在服务器启动时执行 - CSDN博客
Servlet的init()方法如何才会在服务器启动时执行
如果要想让 servlet
() 方法在服务器启动
时就被执行,则需要在 web.xml 中相应的 servlet
&& &servlet
-name&test&/servlet
-class&com.zzk.test.MyServlet&/servlet
&load-on-startup&1&/load-on-startup&
&& &serlvet-name&test&/servlet
&& &url-pattern&/test&/url-pattern&
&load-on-startup&1&/load-on-startup&设置为正整数(包括0)
这样此SERVLET
就会在服务器启动
时执行了。(注意:如果设置为负整数,则不会在启动
服务器时执行)
如果不配置,启动
服务器时也不会执行,而要等此SERVLET
被调用时才会被执行。
本文已收录于以下专栏:
相关文章推荐
tomcat 经常会报一些莫名其妙的异常:如下 type Exception reportmessage description The server encountered an internal ...
servlet中init,service方法
首先你要明确servlet的生命周期和HTTP协议.
Serlvet接口只定义了一个服务方法就是service,而H...
用Eclipse新版本新建servlet时候,发现创建Servlet后,Eclipse不会自动在web.xml中生成该Servlet对应的mapping信息,而是在Servlet代码中加入注解...
今天稍微学习了一下 Servlet,Servlet 主要有以下几个方法:
1) destroy()
2) getServletConfig()
3) getServletInfo()
在Servlet中 javax.servlet.GenericServlet类
继承自java.lang.Object
实现了Serializable,,servlet ,ServletConfi...
容器创建了Servlet实例后,它将调用实例的init(ServletConfig)方法初始化Servlet.该方法的参数ServletConfig对象包含了在WEB应用程序的部署描述文件中指定的初始...
servelt几个主要类的关系如下:
这里说明下为什么我们继承HttpServlet重写doGet()和doPost()后,用户访问时就会调用我们写的方法。实际上用户发送http请求后,由Gener...
init方法是在Servlet实例化之后执行的,并且只执行一次。
一.先说init(ServletConfig)中参数ServletConfig,代表的是配置信息。即在web.xml中配置的信息,比如...
在Servlet中 javax.servlet.GenericServlet类
继承自java.lang.Object
实现了Serializable,,servlet ,ServletConfi...
有时候,我们需要仅仅是在服务启动,而非其他更为复杂的定时任务的时候,做些初始化的工作,比如将一些数据导入到内存中等等,用Servlet的初始化可以很好的做到这一点。而初始化工作是通过Servlet中的...
他的最新文章
讲师:王禹华
讲师:宋宝华
您举报文章:
举报原因:
原文地址:
原因补充:
(最多只允许输入30个字)Tomcat设置默认启动项目及Java Web工程设置默认启动页面 - CSDN博客
Tomcat设置默认启动项目及Java Web工程设置默认启动页面
Tomcat设置默认启动项目
Tomcat设置默认启动项目,顾名思义,就是让可以在浏览器的地址栏中输入ip:8080,就能访问到我们的项目。具体操作如下:
& & 1、打开tomcat的安装根目录,找到Tomcat 6.0\conf\server.xml,打开该文件,找到&Host&节点,在该节点中添加&Context path=&& docBase=&../WebTest& debug=&0& reloadable=&true&/&。
& & 2、再将WebTest工程放到tomcat根目录下,并将webapps文件夹中的ROOT文件夹删除或者重命名为另外一个名字。
& & 3、启动tomcat,在浏览器中输入ip:8080,就可以访问到你的项目了。
&注意:&Context&节点中的docBase属性的值是指向web工程的绝对路径。
& & & & & & & & & & & & & & Web工程设置默认启动页面
Java web工程设置默认启动页面是通过web.xml文件来配置的。具体配置如下:
&servlet-name&StartServlet&/servlet-name&
&servlet-class&NVMP.VideoServer.implement.StartServlet&/servlet-class&
&load-on-startup&0&/load-on-startup&
&/servlet&
&servlet-mapping&
&servlet-name&StartServlet&/servlet-name&
&url-pattern&/StartServlet&/url-pattern&
&/servlet-mapping&
&welcome-file-list&
&welcome-file&login.jsp&/welcome-file&
&/welcome-file-list&
本文已收录于以下专栏:
相关文章推荐
1.关于web应用的首页设置
在tomcat/conf/web.xml文件对首页进行默认设置.
index.html
1:修改server.xml:
2:修改web.xml:
后添加指定的页面
login.jsp...
改变tomcat的默认欢迎界面,也就是说在浏览器中输入http://localhost:8080(端口可以自定义)之后进入的不是tomcat默认的欢迎界
面,而是自定义的虚拟目录myjsp下自定义的...
转载文章,参考地址如下:
http://simen-/blog/1489928
默认web.xml欢迎页面为index.html
我给更改为:
/pages/...
SpringMVC默认访问首页配置及web.xml配置
web.xml文件的作用及基本配置
web工程中的web.xml文件有什么作用呢?它是每个web.xml工程都必须的吗?
一个web中完全可以没有web.xml文件,也就是说,web.xml...
所有修改初始的页面都在项目的web.xml中。idea也不例外
找到项目对应的web.xml
在中添加要初始化的页面
welcome-file-list>
welcome-file...
如何更换Tomcat默认主页
修改配置文件:
首先,修改$tomcat/conf/server.xml文件。
在server.xml文件中,有一段如下:
1、打开server.xml,在的上一行添加内容格式如下
gps" debug="0" reloadable="true"/>
dosBase里写的是你要...
他的最新文章
讲师:王禹华
讲师:宋宝华
您举报文章:
举报原因:
原文地址:
原因补充:
(最多只允许输入30个字)一、修改Servlet的默认模板代码  
  使用MyEclipse创建Servlet时,根据默认的Servlet模板生成的Servlet代码如下:
1 package gacl.servlet.
3 import java.io.IOE
4 import java.io.PrintW
6 import javax.servlet.ServletE
7 import javax.servlet.http.HttpS
8 import javax.servlet.http.HttpServletR
9 import javax.servlet.http.HttpServletR
11 public class ServletDefaultTemplateCode extends HttpServlet {
* The doGet method of the servlet. &br&
* This method is called when a form has its tag value method equals to get.
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType(&text/html&);
PrintWriter out = response.getWriter();
out.println(&&!DOCTYPE HTML PUBLIC \&-//W3C//DTD HTML 4.01 Transitional//EN\&&&);
out.println(&&HTML&&);
out.println(&
&HEAD&&TITLE&A Servlet&/TITLE&&/HEAD&&);
out.println(&
out.print(&
This is &);
out.print(this.getClass());
out.println(&, using the GET method&);
out.println(&
&/BODY&&);
out.println(&&/HTML&&);
out.flush();
out.close();
* The doPost method of the servlet. &br&
* This method is called when a form has its tag value method equals to post.
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType(&text/html&);
PrintWriter out = response.getWriter();
out.println(&&!DOCTYPE HTML PUBLIC \&-//W3C//DTD HTML 4.01 Transitional//EN\&&&);
out.println(&&HTML&&);
out.println(&
&HEAD&&TITLE&A Servlet&/TITLE&&/HEAD&&);
out.println(&
out.print(&
This is &);
out.print(this.getClass());
out.println(&, using the POST method&);
out.println(&
&/BODY&&);
out.println(&&/HTML&&);
out.flush();
out.close();
  在实际开发中,这些生成的代码和注释一般我们都用不到的,每次都要手工删除这些注释和代码,很麻烦,因此可以根据开发的实际情况修改Servlet的模板代码,改成符合实际开发需求的模板代码。下面以MyEclipse 10为例进行说明如何修改Servlet的模板代码
  具体步骤如下:找到MyEclipse安装目录下的\Common\plugins文件夹,比如:D:\MyEclipse10\Common\plugins,然后找到com.genuitec.eclipse.wizards_9.0.0.me.jar这个jar文件,为了方便查找com.genuitec.eclipse.wizards_9.0.0.me.jar这个jar文件,建议使用【SearchEverything】这样的文件查找工具,如下图所示:
  用压缩工具打开,注意是打开不是解压这个jar包,如下图所示:
  打开com.genuitec.eclipse.wizards_9.0.0.me.jar这个jar文件后,可以看到里面有一个templates文件夹,进入templates文件夹,可以看到里面有一个Servlet.java文件,如下图所示:
  打开Servlet.java文件,可以看到里面的模板代码:
1 #---------------------------------------------#
2 # &aw:description&Template for Servlet&/aw:description&
3 # &aw:version&1.1&/aw:version&
4 # &aw:date&04/05/2003&/aw:date&
5 # &aw:author&Ferret Renaud&/aw:author&
6 #---------------------------------------------#
8 &aw:import&java.io.IOException&/aw:import&
9 &aw:import&java.io.PrintWriter&/aw:import&
11 &aw:import&javax.servlet.ServletException&/aw:import&
12 &aw:import&javax.servlet.http.HttpServlet&/aw:import&
13 &aw:import&javax.servlet.http.HttpServletRequest&/aw:import&
14 &aw:import&javax.servlet.http.HttpServletResponse&/aw:import&
16 &aw:parentClass&javax.servlet.http.HttpServlet&/aw:parentClass&
18 &aw:constructor name=&c1&&
* Constructor of the object.
public &aw:className/&() {
26 &/aw:constructor&
28 &aw:method name=&doGet&&
* The doGet method of the servlet. &br&
* This method is called when a form has its tag value method equals to get.
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType(&text/html&);
PrintWriter out = response.getWriter();
out.println(
&&!DOCTYPE HTML PUBLIC \&-//W3C//DTD HTML 4.01 Transitional//EN\&&&);
out.println(&&HTML&&);
out.println(&
&HEAD&&TITLE&A Servlet&/TITLE&&/HEAD&&);
out.println(&
out.print(&
This is &);
out.print(this.getClass());
out.println(&, using the GET method&);
out.println(&
&/BODY&&);
out.println(&&/HTML&&);
out.flush();
out.close();
58 &/aw:method&
60 &aw:method name=&doPost&&
* The doPost method of the servlet. &br&
* This method is called when a form has its tag value method equals to post.
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType(&text/html&);
PrintWriter out = response.getWriter();
out.println(
&&!DOCTYPE HTML PUBLIC \&-//W3C//DTD HTML 4.01 Transitional//EN\&&&);
out.println(&&HTML&&);
out.println(&
&HEAD&&TITLE&A Servlet&/TITLE&&/HEAD&&);
out.println(&
out.print(&
This is &);
out.print(this.getClass());
out.println(&, using the POST method&);
out.println(&
&/BODY&&);
out.println(&&/HTML&&);
out.flush();
out.close();
90 &/aw:method&
92 &aw:method name=&doPut&&
* The doPut method of the servlet. &br&
* This method is called when a HTTP put request is received.
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
public void doPut(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// Put your code here
109 &/aw:method&
111 &aw:method name=&doDelete&&
* The doDelete method of the servlet. &br&
* This method is called when a HTTP delete request is received.
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
public void doDelete(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// Put your code here
128 &/aw:method&
130 &aw:method name=&init&&
* Initialization of the servlet. &br&
* @throws ServletException if an error occurs
public void init() throws ServletException {
// Put your code here
140 &/aw:method&
142 &aw:method name=&destroy&&
* Destruction of the servlet. &br&
public void destroy() {
super.destroy(); // Just puts &destroy& string in log
// Put your code here
151 &/aw:method&
153 &aw:method name=&getServletInfo&&
* Returns information about the servlet, such as
* author, version, and copyright.
* @return String information about this servlet
public String getServletInfo() {
return &This is my default servlet created by Eclipse&;
164 &/aw:method&
&修改该模板,根据自己的实际情况进行修改,比如
  删除doGet和doPost里面的代码和方法注释,在doPost方法里面调用doGet,这是根据实际情况修改成的模板代码,修改好之后,保存,重启MyEclipse,使用MyEclipse创建Servlet,此时就是用刚才修改过的模板进行生成了,生成的代码如下:
1 package gacl.servlet.
3 import java.io.IOE
5 import javax.servlet.ServletE
6 import javax.servlet.http.HttpS
7 import javax.servlet.http.HttpServletR
8 import javax.servlet.http.HttpServletR
10 public class ServletNewTemplateCode extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
二、修改jsp的默认模板
  同样也是找到com.genuitec.eclipse.wizards_9.0.0.me.jar这个jar文件,用压缩工具打开,进入templates\jsp文件夹,可以看到MyEclipse自带的那些jsp模板,如下图所示:
  这些jsp模板是MyEclipse自带的,我们也可以依样画葫芦,根据平时项目开发中的实际情况,创建一个jsp模板,然后添加到jsp目录中,操作步骤如下:
  1、随便复制一个jsp模板出来(如:Jsp.vtl),复制到系统的桌面或者系统的其他盘进行存储
  2、修改复制出来的模板,使用记事本或者editplus打开Jsp.vtl,可以看到Jsp.vtl的模板代码,如下所示:
1 #*---------------------------------------------#
2 # Template for a JSP
3 # @version: 1.2
4 # @author: Ferret Renaud
5 # @author: Jed Anderson
6 #---------------------------------------------#
7 *#&%@ page language=&java& import=&java.util.*& pageEncoding=&$encoding&%&
9 String path = request.getContextPath();
10 String basePath = request.getScheme()+&://&+request.getServerName()+&:&+request.getServerPort()+path+&/&;
13 &!DOCTYPE HTML PUBLIC &-//W3C//DTD HTML 4.01 Transitional//EN&&
&base href=&&%=basePath%&&&
&title&My JSP '$title' starting page&/title&
#parse( &templates/jsp/JSPMetaTags.vtl& )
This is my JSP page. &br&
26 &/html&
  这是Jsp.vtl的模板原始代码,这个模板的代码对于我来说不太符合项目开发中的实际情况,需要修改,修改后的模板如下:
1 #*---------------------------------------------#
2 # Template for a JSP
3 # @version: 1.2
4 # @author: 孤傲苍狼
5 #---------------------------------------------#
6 *#&%@ page language=&java& pageEncoding=&UTF-8&%&
7 &!DOCTYPE HTML&
&title&&/title&
16 &/html&
  为了避免覆盖原来的Jsp.vtl模板,将修改后的Jsp.vtl模板重命名,例如重命名成gacl.vtl。
  3.将gacl.vtl模板复制,然后粘贴到com.genuitec.eclipse.wizards_9.0.0.me.jar包里面的templates\jsp文件夹里。
  4、从查看解压文件的界面中,返回到根目录(即com.genuitec.eclipse.wizards_9.0.0.me.jar目录),找到模版配置文件templates.xml,如下图所示:
  同样,将templates.xml文件复制到桌面,使用记事本或者editplus打开进行修改。
  修改如下:在&templateLibrary&里添加如下元素:
1 &template
context=&com.genuitec.eclipse.wizards.jsp&
script=&templates/jsp/gacl.vtl&
name=&gacl-JSP template&/&
  1、templates/jsp/gacl.vtl:为新添加的jsp模板的相对路径。&
  2、gacl-JSP template:为MyEclipse中所要标识的模版名称,MyEclipse新建JSP文件时通过这个名字来选择对应的模版。&
  3、context=&com.genuitec.eclipse.wizards.jsp&& 这个一定要存在,并且跟其他jsp模板的设置一样,复制就可以。
templates.xml修改后的内容如下图所示:
  5、修改完成后,将com.genuitec.eclipse.wizards_9.0.0.me.jar包中的templates.xml文件删除掉,然后将修改过后的templates.xml复制,粘贴到com.genuitec.eclipse.wizards_9.0.0.me.jar包中,如下图所示:
  到此,我们的Jsp模板就算是创建好了。
  6.启动MyEclipse,然后新创建一个Jsp页面,此时就可以使用我们自定义的那个Jsp页面模板了,如下图所示:
  通过以上两种方式,我们在开发的时候,就可以根据我们自己的开发习惯来定制servlet和jsp的模板了,对于开发效率上或多或少有一点提高吧,不用每次都把MyEclipse生成的很多用不到的代码删掉。
本文已收录于以下专栏:
相关文章推荐
一、修改Servlet的默认模板代码  
  使用MyEclipse创建Servlet时,根据默认的Servlet模板生成的Servlet代码如下:
1 package gacl.s...
很多门户网站,都会把自己的首页作为网站的欢迎页面。设置完欢迎页面过后,用户登录时输入的URL只需为该门户网站的虚拟路径时就可以自动的访问欢迎页面。这个可修改web.xml中的一个设置项,代码如下:
转载文章,参考地址如下:
http://simen-/blog/1489928
默认web.xml欢迎页面为index.html
我给更改为:
/pages/...
1、欢迎页面怎么设置?
* 假设在WebContent目录下创建login.html,想让login.html作为整个webapp的欢迎页面,应该做这样的设置,编写web.xml文件:
修改MyEclipse中的Jsp页面模板和默认编码模式
每次用MyEclipse新建Jsp页面,都要删除一些无用的代码,修改pageEncoding. 今天从网上搜索了一下修改Jsp页面模本...
myeclipse的安装路径\plugins\com.genuitec.eclipse.wizards_11.5.0.me.jar
找到servlet.java;把此文件拖...
MyEclipse使用总结——在MyEclipse中设置jsp页面为默认utf-8编码
在MyEclispe中创建Jsp页面,Jsp页面的默认编码是“ISO-8859-1”,如下图所示:
首先我们打开Myeclipse8.5,设置jsp的编码方式我们是在window-perference中设置。通常设置都在Perference中进行设置。
文章来源:/article/656db918bcb541e.html   
作为企业级开发最流行的工具,用Myeclipse开发ja...
本文属于主要MyEclipse使用教程,也是这段时间打算写的方向,就当做MyEclipse使用方面一些小总结。本文介绍了在MyEclipse如何设置jsp页面为默认utf-8编码,具体设置如下:
他的最新文章
讲师:钟钦成
讲师:宋宝华
您举报文章:
举报原因:
原文地址:
原因补充:
(最多只允许输入30个字)本帖子已过去太久远了,不再提供回复功能。2016年10月 Java大版内专家分月排行榜第一2016年9月 Java大版内专家分月排行榜第一2016年8月 Java大版内专家分月排行榜第一2014年4月 Java大版内专家分月排行榜第一
2016年11月 Java大版内专家分月排行榜第二
2016年1月 Java大版内专家分月排行榜第二2015年12月 Java大版内专家分月排行榜第二2015年8月 Java大版内专家分月排行榜第二2015年3月 Java大版内专家分月排行榜第二2015年1月 Java大版内专家分月排行榜第二2014年12月 Java大版内专家分月排行榜第二2014年11月 Java大版内专家分月排行榜第二2014年6月 Java大版内专家分月排行榜第二2014年4月 Java大版内专家分月排行榜第二2014年1月 Java大版内专家分月排行榜第二2013年11月 Java大版内专家分月排行榜第二
2015年9月 Java大版内专家分月排行榜第三2015年6月 Java大版内专家分月排行榜第三2015年5月 Java大版内专家分月排行榜第三2015年2月 Java大版内专家分月排行榜第三2014年3月 Java大版内专家分月排行榜第三2013年12月 Java大版内专家分月排行榜第三
2013年10月 总版技术专家分月排行榜第三
2014年3月 Java大版内专家分月排行榜第一2014年1月 Java大版内专家分月排行榜第一2013年12月 Java大版内专家分月排行榜第一2013年11月 Java大版内专家分月排行榜第一2013年10月 Java大版内专家分月排行榜第一
2016年10月 Java大版内专家分月排行榜第一2016年9月 Java大版内专家分月排行榜第一2016年8月 Java大版内专家分月排行榜第一2014年4月 Java大版内专家分月排行榜第一
2016年11月 Java大版内专家分月排行榜第二
2013年11月 扩充话题大版内专家分月排行榜第二
本帖子已过去太久远了,不再提供回复功能。}

我要回帖

更多关于 servlet的功能 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信