适合美工的设计网站,上海金融网站建设公司,工程业绩在哪个平台上查询,网站服务器租用阿里云一年多少钱啊- 什么是一个web站点的欢迎页面#xff1f; - 对于一个webapp来说#xff0c;我们是可以设置它的欢迎页面的。 - 设置了欢迎页面之后#xff0c;当你访问这个webapp的时候#xff0c;或者访问这个web站点的时候#xff0c;没有指定任何“资源路径”#xff0c;这个时候…
- 什么是一个web站点的欢迎页面 - 对于一个webapp来说我们是可以设置它的欢迎页面的。 - 设置了欢迎页面之后当你访问这个webapp的时候或者访问这个web站点的时候没有指定任何“资源路径”这个时候会默认访问你的欢迎页面。 - 我们一般的访问方式是 - http://localhost:8080/servlet06/login.html 这种方式是指定了要访问的就是login.html资源。 - 如果我们访问的方式是 - http://localhost:8080/servlet06 如果我们访问的就是这个站点没有指定具体的资源路径。它默认会访问谁呢 - 默认会访问你设置的欢迎页面。
- 怎么设置欢迎页面呢 - 第一步我在IDEA工具的web目录下新建了一个文件login.html - 第二步在web.xml文件中进行了以下的配置 - xml welcome-file-list welcome-filelogin.html/welcome-file /welcome-file-list - 注意设置欢迎页面的时候这个路径不需要以“/”开始。并且这个路径默认是从webapp的根下开始查找。 - 第三步启动服务器浏览器地址栏输入地址 - http://localhost:8080/servlet07
- 如果在webapp的根下新建一个目录目录中再给一个文件那么这个欢迎页该如何设置呢 - 在webapp根下新建page1 - 在page1下新建page2目录 - 在page2目录下新建page.html页面 - 在web.xml文件中应该这样配置 - welcome-file-list welcome-filepage1/page2/page.html/welcome-file /welcome-file-list - 注意路径不需要以“/”开始并且路径默认从webapp的根下开始找。
- 一个webapp是可以设置多个欢迎页面的 - xml welcome-file-list welcome-filepage1/page2/page.html/welcome-file welcome-filelogin.html/welcome-file /welcome-file-list - 注意越靠上的优先级越高。找不到的继续向下找。
- 你有没有注意一件事当我的文件名设置为index.html的时候不需要在web.xml文件中进行配置欢迎页面。这是为什么 - 这是因为Tomcat服务器已经提前配置好了。 - 实际上配置欢迎页面有两个地方可以配置 - 一个是在webapp内部的web.xml文件中。在这个地方配置的属于局部配置 - 一个是在CATALINA_HOME/conf/web.xml文件中进行配置。在这个地方配置的属于全局配置 - xml welcome-file-list welcome-fileindex.html/welcome-file welcome-fileindex.htm/welcome-file welcome-fileindex.jsp/welcome-file /welcome-file-list - Tomcat服务器的全局欢迎页面是index.html index.htm index.jsp。如果你一个web站点没有设置局部的欢迎页面Tomcat服务器就会以index.html 或者index.htm或者 index.jsp作为一个web站点的欢迎页面。 - 注意原则局部优先原则。就近原则
- 欢迎页可以是一个Servlet吗 - 当然可以。 - 欢迎页就是一个资源既然是一个资源那么可以是静态资源也可以是动态资源。 - 静态资源index.html welcome.html ..... - 动态资源Servlet类。 - 步骤 - 第一步写一个Servlet - java public class WelcomeServlet extends HttpServlet { Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType(text/html); PrintWriter out response.getWriter(); out.print(h1welcome to bjpowernode!/h1); } } - 第二步在web.xml文件中配置servlet - xml servlet servlet-namewelcomeServlet/servlet-name servlet-classcom.bjpowernode.javaweb.servlet.WelcomeServlet/servlet-class /servlet servlet-mapping servlet-namewelcomeServlet/servlet-name url-pattern/fdsa/fds/a/fds/af/ds/af/dsafdsafdsa/url-pattern /servlet-mapping - 第三步在web.xml文件中配置欢迎页 - xml welcome-file-list welcome-filefdsa/fds/a/fds/af/ds/af/dsafdsafdsa/welcome-file /welcome-file-list