熟悉的代码:
<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映射?
我收到了这个重要的新手问题.当我尝试以下; '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.