首页 > 关于servlet运行问题

关于servlet运行问题

首相说明一下,我是新手,对于帮助我的人,我表示感谢!

问题:这个servlet是跟着视频做的,步骤我感觉都是对的,但是就是运行不出来,已经困扰了我一段时间,学习就卡在了这里

相关java代码和web.xml代码:

package ww;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class HelloWordServlet extends HttpServlet {

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    System.out.println("doGet");
    response.getWriter().write("<a href='www.baidu.com'>go</a>");
}

}

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" id="WebApp_ID"

xmlns="http://java.sun.com/xml/ns/javaee" 
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">

<!-- 配置Servlet -->

<servlet>
    <servlet-name>HW</servlet-name>
    <servlet-class>HelloWordServlet</servlet-class>
</servlet>
<!-- 配置Servlet映射路径 -->
<servlet-mapping>
    <servlet-name>HW</servlet-name>
    <url-pattern>/abc</url-pattern>
</servlet-mapping>

</web-app>


abc前面的ww是你的contextpath吗?不是就去掉。


这个你是怎么部署到tomcat的,搜索下tomcat的contextpath配置你就明白了


好久没看了,class地址我记得要用全名,加上包试试ww.Hello


1、在web.xml中配置servlet时需要使用类全名;
2、访问servlet:http:hostname:port/projectName/urlMapping


那个配置类路径,需要全名!你试试

【热门文章】
【热门文章】