我刚开始使用servlet,我是一个新手。我用一个调用servlet的提交按钮开发了一个html页面。这里是它的html代码。运行servlet应用程序时获得空白屏幕
<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.
如果我错了???
你有stacktrace吗?如果是这样,请发布。 – mthmulders
http:// localhost:8080/Revisio/Idiot拼写检查“修订”? – Metalhead
@Metalhead:我检查了正确的拼写。这不是问题 其次,我正在屏幕上获取html页面,并且我没有直接访问servlet。请参阅它通过部署描述符映射。单击提交按钮 –