标签: welcome-file

如何在web.xml中配置欢迎文件列表

我在我的web.xml文档中有这个.我想要一个欢迎列表,所以我不需要再输入主页的路径了.但每次单击我的tomcat页面中的应用程序时,它都会显示所请求的资源不可用.

<listener>
    <listener-class>web.Init</listener-class>
</listener>

<welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
</welcome-file-list>

<servlet>
    <servlet-name>index</servlet-name>
    <servlet-class>web.IndexServlet</servlet-class>
</servlet>

<servlet-mapping>
    <servlet-name>index</servlet-name>
    <url-pattern>/index</url-pattern>
</servlet-mapping>
Run Code Online (Sandbox Code Playgroud)

我的jsp页面的servlet

package web;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;

public class IndexServlet extends HttpServlet
{
    private Logger logger = Logger.getLogger(this.getClass());
    private RequestDispatcher jsp;

    public void init(ServletConfig config) throws ServletException
    {
        ServletContext context = config.getServletContext();
        jsp = context.getRequestDispatcher("/WEB-INF/jsp/index.jsp");
    }

    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
    {
        logger.debug("doGet()");
        jsp.forward(req, resp); 
    }
} …
Run Code Online (Sandbox Code Playgroud)

jsp web.xml servlets welcome-file

37
推荐指数
2
解决办法
21万
查看次数

如何在WebApplicationInitializer.onStartup()中指定welcome-file-list

目前我有一个Web应用程序,我们使用web.xml来配置应用程序.web.xml有welcome-file-list.

<web-app>  
   ...
   <welcome-file-list>  
     <welcome-file>home.html</welcome-file>  
   </welcome-file-list>  
</web-app>  
Run Code Online (Sandbox Code Playgroud)

我们计划使用spring框架并使用java类进行应用程序配置.

class MyApplication extends WebApplicationInitializer {
    public void onStartUp(ServletContext context){
        ...
    }
}
Run Code Online (Sandbox Code Playgroud)

如何在此java类中指定welcome-file-list?

spring web.xml welcome-file programmatic-config

15
推荐指数
3
解决办法
2万
查看次数

在JSF项目中通过<welcome-file>设置默认主页

当我使用Eclipse中的Tomcat 8.0启动Java EE项目时,我无法设置在浏览器中加载的默认页面.我正在尝试学习JSF,所以我遵循了本教程

一切正常,但是当我右键单击login.xhtmlwelcome.xhtml文件并选择"在服务器上运行/运行" 时,我只能看到创建的页面.

到目前为止,我创建的所有其他Web应用程序在我启动整个项目时都加载了默认页面.默认行为是加载index.html页面(如果有的话,可能是index.jsp).所以我添加index.htmlindex.xhtml页面到我的WEB-INF项目文件夹,希望其中至少有一个将被显示.然而,没有任何反应.浏览器始终只显示localhost:8080/JSFFaceletsTutorial/URL 上的页面,但页面是白色的,甚至不是错误消息.我想我一直在解决这个问题的过程中遇到错误404,但是,我不再能够重现这个错误,我不记得是什么导致了它.

我发现可以更改默认的起始页面

但是,它对我也不起作用.无论我是否编辑web.xml文件,我都得到相同的结果.

更令人费解的是,当我尝试更改网络浏览器时:"窗口/网络浏览器/ ..."它在外部网络浏览器中的作用时间与内部Eclipse网络浏览器不同.内部总是空白页面 - 但外部网络浏览器曾经设法显示index.html页面 - 但它是一些过时的版本.尽管我完全确定我编辑了它,保存了更改,重新启动了服务器......但它仍然显示了页面的过时版本.即使在这种情况下,它仍然忽略了web.xml文件中所做的更改.但是当我现在尝试它时,它再次在所有浏览器中显示空白页面.除了编辑web.xml文件外,我不知道我做了什么改变......

我的猜测是问题在于我还没有完全掌握的JSF技术.这是因为当我选择使用右键单击"运行方式/在服务器上运行" 来运行login.xhtmlwelcome.xhtml页面时,这些页面的URL将显示localhost:8080:路径/JSFFaceletsTutorial/faces/login.xhtml/JSFFaceletsTutorial/faces/welcome.xhtml.这很奇怪,因为我的项目中没有任何目录"faces".键入所有可能的排列:

<welcome-file-list>
    <welcome-file>faces/index.html</welcome-file>
    <welcome-file>faces/index.xhtm</welcome-file>
</welcome-file-list>
Run Code Online (Sandbox Code Playgroud)

在这web.xml也没有帮助.当我在那里输入完整地址时,它没有帮助.

以下是我在控制台中收到的警告(我跳过了INFO日志条目):

"2014年12月19日上午9:39:55 org.apache.tomcat.util.digester.SetPropertiesRule开始警告:[SetPropertiesRule] {Server/Service/Engine/Host/Context}将属性'source'设置为'org.eclipse. jst.jee.server:JSFFaceletsTutorial'找不到匹配的属性....警告:JSF1074:已经注册了名为'loginBean'的托管bean.用com.tutorial.LoginBean替换现有的托管bean类com.tutorial.LoginBean .2014年12月19日上午9:39:57 org.apache.coyote.AbstractProtocol start"

我不确定这是否有用.我现在没有想法了.

eclipse jsf tomcat homescreen welcome-file

9
推荐指数
1
解决办法
2万
查看次数

如何在Jersey容器中配置欢迎文件(HTML/JSP)

我有一个Jersey RESTful Web服务项目.我在web.xml中配置了Jersey容器,一切正常.

在同一个项目中,我引入了一个HTML页面并包含在<welcome-file-list>处理其他一些非REST请求中.但是当我访问URL时,不会显示欢迎文件.

我在web.xml中评论Jersey容器配置并部署了应用程序后,这次我可以访问欢迎文件.

我使用的是Tomcat 7,JDK 7,Jersey 2.2和Eclipse Juno.Jersey配置后如何使欢迎文件正常工作?Jersey有没有限制,还是需要以不同的方式配置才能实现这一点?

我的web.xml:

<?xml version="1.0" encoding="UTF-8"?>
 <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com /xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>My Service</display-name>
  <servlet>
    <servlet-name>Jersey REST Service</servlet-name>
    <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
    <init-param>
      <param-name>jersey.config.server.provider.packages</param-name>
      <param-value>com.my.rest.service</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>    
  </servlet>
  <servlet-mapping>
    <servlet-name>Jersey REST Service</servlet-name>
    <url-pattern>/*</url-pattern>
 </servlet-mapping>      
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file> 
  </welcome-file-list>
</web-app>
Run Code Online (Sandbox Code Playgroud)

java rest servlets jersey welcome-file

8
推荐指数
2
解决办法
2万
查看次数

如何在index.jsp上加载servlet

有没有办法调用servlet index.jsp?我的欢迎档案是index.jsp.我需要在index.jsp打开时通过servlet填充下拉列表值.

我试图设置<load-on-startup>web.xml,但没有任何效果.如何获取欢迎文件index.jsp来调用servlet?

jsp servlets welcome-file

6
推荐指数
1
解决办法
3万
查看次数

欢迎文件在春天不使用html文件

我在web.xml中提供了我的欢迎文件但是在运行应用程序时,它显示404错误 http://172.16.2.16:8080/sampletest/

这是一个春季应用程序.

web.xml中

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://xmlns.jcp.org/xml/ns/javaee"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
    id="WebApp_ID" version="3.1">
    <display-name>sampletest</display-name>
    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
    </welcome-file-list>

    <!-- Spring MVC -->
    <servlet>
        <servlet-name>dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>dispatcher</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
</web-app>
Run Code Online (Sandbox Code Playgroud)

我正在使用eclipse luna,java 8,tomcat 8和maven框架.index.html文件直接位于webapp文件夹下,web.xml位于webapp/WEB-INF文件夹下. 如果我使用index.jsp而不是index.html,它就可以了.然后欢迎页面将加载使用http://172.16.2.16:8080/sampletest/

问题仅在于欢迎文件.否则弹簧配置正常. http://localhost:8080/sampletest/test/将从数据库加载数据.

控制台中的错误日志

......................

Jul 10, 2014 12:38:42 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 4963 ms
Jul 10, 2014 12:38:42 PM org.springframework.web.servlet.DispatcherServlet noHandlerFound
WARNING: No mapping found for HTTP request with URI [/sampletest/] in DispatcherServlet with name 'dispatcher'
Run Code Online (Sandbox Code Playgroud)

的index.html

<!DOCTYPE …
Run Code Online (Sandbox Code Playgroud)

html spring jsp maven welcome-file

5
推荐指数
2
解决办法
3万
查看次数

在 web.xml 中将 servlet 设置为默认主页

我在web.xml下面注册了一个 servlet 。

<servlet>
    <servlet-name>Manager</servlet-name>
    <servlet-class>Manager</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>Manager</servlet-name>
    <url-pattern>/RequestManager</url-pattern>
</servlet-mapping>
Run Code Online (Sandbox Code Playgroud)

基本上,当我打开http://localhost:8080/appname. 因此,我尝试将其注册为欢迎文件,web.xml如下所示:

<welcome-file-list>
    <welcome-file>Manager</welcome-file>
</welcome-file-list>
Run Code Online (Sandbox Code Playgroud)

但是,当我运行该项目时,我收到一条错误消息,提示“请求的资源不可用”。但是,如果我用我的 servlet URL 模式在 url 中写入,它就可以正常工作。

web.xml servlets welcome-file

5
推荐指数
1
解决办法
2万
查看次数

HTTP状态404 - 请求的资源(/ ProjectName /)不可用

在Tomcat服务器上运行Eclipse项目时出现以下错误:

HTTP状态404 - 请求的资源(/ ProjectName /)不可用.

浏览器地址栏中的URL是http://localhost:8080/ProjectName/.

我真的不知道我的文件中缺少什么.我Index.jsp/WebContent文件夹中有一个我的web.xml包含在下面的条目:

<welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
</welcome-file-list>
Run Code Online (Sandbox Code Playgroud)

eclipse jsp tomcat http-status-code-404 welcome-file

4
推荐指数
1
解决办法
7万
查看次数

欢迎文件忽略安全性约束

我的web.xml:

    <context-param>
            <param-name>javax.faces.PROJECT_STAGE</param-name>
            <param-value>Development</param-value>
        </context-param>

        <welcome-file-list>
            <welcome-file>/secured/secure.xhtml</welcome-file>
        </welcome-file-list>

        <servlet>
            <servlet-name>Faces Servlet</servlet-name>
            <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
            <load-on-startup>1</load-on-startup>
        </servlet>

        <servlet-mapping>
            <servlet-name>Faces Servlet</servlet-name>
            <url-pattern>*.xhtml</url-pattern>
        </servlet-mapping>

        <context-param>
            <param-name>javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL</param-name>
            <param-value>true</param-value>
        </context-param> 
    <security-constraint>
        <web-resource-collection>
          <web-resource-name>Restricted</web-resource-name>
          <url-pattern>/secured/*</url-pattern>
          <http-method>GET</http-method>
          <http-method>POST</http-method>
        </web-resource-collection>
        <auth-constraint>
          <role-name>ADMIN</role-name>
        </auth-constraint>
      </security-constraint>
<login-config>
     <auth-method>FORM</auth-method>
     <realm-name>jdbc-realm</realm-name>
     <form-login-config>
       <form-login-page>/public/login.xhtml</form-login-page>
       <form-error-page>/public/error.xhtml</form-error-page>
     </form-login-config>
   </login-config>
Run Code Online (Sandbox Code Playgroud)

我希望我的网络应用程序将未经授权的用户重定向到登录页面.有趣的事情我有这个工作,但我做了一些愚蠢的更改,现在访问localhost:8080我总是看到secure.xhtml即使没有登录.localhost:8080/secured/secure.xhtml重定向很好.

jsf servlets security-constraint welcome-file

3
推荐指数
1
解决办法
3181
查看次数

在使用基于纯Java的配置而不是web.xml开发spring mvc应用程序时如何设置welcome-file?

我正在使用Spring MVC开发一个Web应用程序,它基于纯Java,没有web.xml配置.我编写了下面的类来加载bean并设置url模式.如何设置welcome-file?

public class MyAppWebAppIntializer implements WebApplicationInitializer {
    @Override
    public void onStartup(ServletContext servletContext) throws ServletException {
        AnnotationConfigWebApplicationContext appCtx = new AnnotationConfigWebApplicationContext();
        appCtx.register(ApplicationContextConfig.class);

        Dynamic dispatcher = servletContext.addServlet(
                "SpringDispatcher", new DispatcherServlet(appCtx));
        dispatcher.setLoadOnStartup(1);
        dispatcher.addMapping("/");
    }
}
Run Code Online (Sandbox Code Playgroud)

configuration spring spring-mvc welcome-file

2
推荐指数
1
解决办法
3014
查看次数