我剛開始使用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。請參閱它通過部署描述符映射。單擊提交按鈕 –