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

无法解析符号'servlet'

我收到了这个重要的新手问题.当我尝试以下; 'servlet'变为红色并指示'无法解析符号'servlet'.

import javax.servlet.http.*;
import javax.servlet.ServletException;
Run Code Online (Sandbox Code Playgroud)

我得到了apache tomcat运行.我是一个非常大的java新手.任何人都可以帮助我在哪里找到一个servlet库或什么?我用谷歌搜索,但没有明确解释如何使这项工作.

这是我的web.xml文件的内容;

<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
         version="2.5">

    <display-name>
        HelloWorld
    </display-name>
    <description>
        This is my first webapp
    </description>

    <servlet>
        <servlet-name>Hello world!</servlet-name>
        <description>This is a hello world servlet</description>
        <servlet-class>servlet</servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>HelloWorldServlet</servlet-name>
        <url-pattern>HelloWorldServlet</url-pattern>
    </servlet-mapping>

</web-app>
Run Code Online (Sandbox Code Playgroud)

编辑:我使用IntelliJ IDEA IDE.我正在使用Maven.

java servlets web-applications

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

标签 统计

servlets ×2

java ×1

url-pattern ×1

web-applications ×1

web.xml ×1