相关疑难解决方法(0)

servlet映射url模式中/和/*之间的区别

熟悉的代码:

<servlet-mapping>
    <servlet-name>main</servlet-name>
    <url-pattern>/*</url-pattern>
</servlet-mapping>

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

我的理解是/*地图http://host:port/context/*.

怎么样/?它肯定不会映射到http://host:port/contextroot.事实上,它会接受http://host:port/context/hello,但拒绝http://host:port/context/hello.jsp.

任何人都可以解释如何http://host:port/context/hello映射?

web.xml servlets url-pattern

171
推荐指数
4
解决办法
17万
查看次数

使用doGet将根路径中的默认主页更改为servlet

我有一个小maven(间接通过Netbeans 8.1和tomcat设置)

每当我运行项目时,它会在根目录上打开带有HelloWord的浏览器:

即页面http://localhost:8084/是:

<html>
    <head>
        <title>Start Page</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    </head>
    <body>
        <h1>Hello World!</h1>
    </body>
</html>
Run Code Online (Sandbox Code Playgroud)

我试图创建一个servlet来替换它:

@WebServlet(name = "HomeServlet", urlPatterns = {"/"}) 但是,它没有按预期工作.

即它仍然表现出同样的问候世界: http://localhost:8084

但它确实搞乱了根目录上的所有文件,即http://localhost:8084/foo.css由这个servlet处理并获得响应.

所以,我的问题是(实际上是两个):

如何将此页面的内容更改为其他内容?

或者,至少(如果前者不可能):我可以在根路径上使用永久重定向来避免用户看到此页面吗?

(即http代码301)将用户移动到 http://localhost:8084/home

servlets homescreen

10
推荐指数
1
解决办法
5613
查看次数

如何使用子文件夹作为web.xml欢迎目录

我想为Google App Engine配置我的web.xml,但我的配置不起作用.我想更改默认index.html用WebApp/index.html.

这是web.xml:

<servlet>
    <servlet-name>App</servlet-name>
    <servlet-class>bg.app.AppServlet</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>App</servlet-name>
    <url-pattern>/WebApp/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
    <welcome-file>WebApp/index.html</welcome-file>
</welcome-file-list>
Run Code Online (Sandbox Code Playgroud)

java google-app-engine web.xml servlets

8
推荐指数
1
解决办法
8316
查看次数

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万
查看次数