Tim幸运之裤 2020-04-30 21:32 采纳率: 0%
浏览 300

用NetBeans和tomcat遇到HTTP Status 500;

我用NetBeans 11.1 + JDK 11.0.2+ tomcat 9.0.31创建了一个简单的HelloWorld项目,部署是成功了在tomcat对应的conf/Catalina/localhost/文件夹下有HelloWorld.xml生成,但是访问http://localhost:8080/HelloWorld/ServletHello 报出HTTP Status 500。这是ServletHello.java代码

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package test;

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author TIM
 */
public class ServletHello extends HttpServlet {

    public void doGet (HttpServletRequest request,
                       HttpServletResponse response) 
      throws ServletException, IOException
        {
          // Set the HTTP content type in response header
          response.setContentType("text/html; charset=\"UTF-8\"");

          // Obtain a PrintWriter object for creating the body
          // of the response
          PrintWriter servletOut = response.getWriter();

          // Create the body of the response
          servletOut.println(
"<!DOCTYPE html \n" +
"    PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \n" +
"    \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\"> \n" +
"<html xmlns='http://www.w3.org/1999/xhtml'> \n" +
"  <head> \n" +
"    <title> \n" +
"      ServletHello.java \n" +
"    </title> \n" +
"  </head> \n" + 
"  <body> \n" +
"    <p> \n" + 
"       Hello World! \n" +
"    </p> \n" +
"  </body> \n" +
"</html> ");
          servletOut.close();
        }

}

图片说明图片说明

  • 写回答

1条回答 默认 最新

  • threenewbee 2020-05-01 11:06
    关注

    加上

    @Override
    public void init(ServletConfig config) throws ServletException {
    // TODO Auto-generated method stub
    super.init(config);
    }
    看看

    评论

报告相同问题?

悬赏问题

  • ¥50 易语言把MYSQL数据库中的数据添加至组合框
  • ¥20 求数据集和代码#有偿答复
  • ¥15 关于下拉菜单选项关联的问题
  • ¥20 java-OJ-健康体检
  • ¥15 rs485的上拉下拉,不会对a-b<-200mv有影响吗,就是接受时,对判断逻辑0有影响吗
  • ¥15 使用phpstudy在云服务器上搭建个人网站
  • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
  • ¥15 vue3+express部署到nginx
  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况