【问题标题】:Getting empty screen when running servlet application [closed]运行servlet应用程序时出现空白屏幕[关闭]
【发布时间】:2012-10-22 13:05:53
【问题描述】:

我刚刚开始研究 servlet,我是新手。我开发了一个带有调用 servlet 的提交按钮的 html 页面。这是它的 html 代码。

<html>
<head>
<title>A simple revision of servlets</title>
</head>
<body>
<form method="POST" action="Idiot">
    <input type="SUBMIT">
</form>
</body>
</html>

部署描述符如下命名为web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app 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/web-app_2_5.xsd"
version="2.5">
<servlet>
<servlet-name>TangoCharlie</servlet-name>
<servlet-class>com.example.web.Revise</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>TangoCharlie</servlet-name>
<url-pattern>/Idiot</url-pattern>
</servlet-mapping>
</web-app>

servlet的代码如下,命名为:Revise.java

package com.example.web;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;

public class Revise extends HttpServlet
{
public void doPost(HttpServletRequest request,HttpServletResponse response) throws IOException,ServletException
{
    response.setContentType("text/html");
    PrintWriter out=response.getWriter();
    //out.println("<html><body><h3>Hello</h3></body></html>");
    out.println("Hello");
}
} 

我在 tomcat 服务器的 webapps 中维护了以下目录。 webapps->Revision->page.html

webapps->Revision->WEB-INF->web.xml

webapps->Revision->WEB-INF->classes->com->example->web->Revise.class

当我在 Mozilla Firefox 中运行 page.html 并单击提交时,我得到一个空白页。 当我在 Chrome 中运行 page.html 时,我收到以下消息:

Server error
The website encountered an error while retrieving http://localhost:8080/Revision/Idiot.It may be down for maintenance or configured incorrectly.
Here are some suggestions:
Reload this webpage later.
HTTP Error 500 (Internal Server Error): An unexpected condition was encountered while the server was attempting to fulfill the request.

我哪里错了???

【问题讨论】:

  • 你有堆栈跟踪吗?如果有,请发布。
  • localhost:8080/Revisio/Idiot "Revision" 的拼写检查?
  • @Metalhead:我已经正确检查了拼写。这不是问题其次,我在屏幕上看到了 html 页面,我没有直接访问 servlet。看到它是通过部署描述符映射的。点击提交按钮后出现问题
  • 尝试把url-pattern改成这样:/Idiot/
  • 您是否尝试过重新部署它?这里似乎没有任何代码问题。

标签: java jakarta-ee web-applications


【解决方案1】:

http://localhost:8080/Revisio/Idiot

查看 typoRevisionNot Revisio

【讨论】:

    【解决方案2】:

    正如@Metalhead 所建议的,我只需要重新启动 tomcat。

    错字“Revisio”是我在复制和粘贴过程中的错误,因为 chrome 上的页面在右侧展开,我错过了“修订”中的字符“n”。对此我深表歉意。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-12-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多