相关疑难解决方法(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万
查看次数

使用Tomcat 7的@WebServlet注释

在我的应用程序中,我有一个servlet,在web.xml中定义如下:

<servlet>
    <display-name>Notification Servlet</display-name>
    <servlet-name>NotificationServlet</servlet-name>
    <servlet-class>com.XXX.servlet.NotificationServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>NotificationServlet</servlet-name>
    <url-pattern>/notification/*</url-pattern>
</servlet-mapping>
Run Code Online (Sandbox Code Playgroud)

在使用Tomcat 7之后,我想使用@WebServlet将完成这项工作的注释.
这是我做的方式:

@WebServlet( name="NotificationServlet", displayName="Notification Servlet", urlPatterns = {"/notification"}, loadOnStartup=1)
public class NotificationServlet extends HttpServlet {
Run Code Online (Sandbox Code Playgroud)

它不起作用.有人可以告诉我我做错了什么吗?

annotations servlets servlet-3.0 tomcat7

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

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

如何使用子文件夹作为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
查看次数

如何设置Servlet作为Java中的主页运行?

我正在尝试使用Java中的Tomcat创建一个简单的Web项目.

在web.xml文件中,我指向一个我希望在有人访问时运行的servlet http://localhost:8080/MyProject,因此我将其/用作URL模式.这有用,但是它的缺点是所有到html和javascript文件的链接都被传递到主servlet而不是相应的文件本身.将Url模式更改/为/Home或/Main修复它.

我究竟做错了什么?

java tomcat servlets

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

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

首先在Java Web应用程序中调用默认servlet

SampleServlet每当我以这种方式访问​​我的java Web应用程序时,我希望首先调用我:

http://server:8080/appname/

有没有办法实现这个?

java servlets

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