简单的 servlet 项目(HTTP 状态 404 错误) [英] Simple servlet project (HTTP Status 404 error)
问题描述
我想创建一个 servlet 项目.
I want to create a servlet project.
我的 Java 类名为 AzpanaServlet.java
,它包含一个内部类.(当我编译它时,我有 2 个类文件).
My Java class is called AzpanaServlet.java
, and it contains an inner class. (When I compile it, I have 2 class files).
我的项目是一个简单的应用程序,它接收一个字符串输入并用它做一些事情(不相关).
My project is a simple application that receives a string input and does some stuff with it (not relevant).
当我按下 "submit"
按钮时,我收到以下错误:
When I press on the "submit"
button I receive the following error:
HTTP Status 404 - /AzpanaServlet
Type Status report
Message /AzpanaServlet
Description The requested resource (/AzpanaServlet) is not available.
Apache Tomcat/6.0.18
如果可以,请帮助我,我解决不了这么多时间.这是我的 Java 代码:
Please help me if you can, I can't solve this much time. this is my Java code:
public class AzpanaServlet extends HttpServlet {
//
//Some functions
//
//Inner class: public class oneChar{...}
//
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
/*
* Get the value of form parameter
*/
String name = request.getParameter("name");
/*
* Set the content type(MIME Type) of the response.
*/
response.setContentType("text/html");
String str = "";
PrintWriter out = response.getWriter();
ArrayList<Integer> list = new ArrayList<Integer>();
try {
list = mainmanu(name); //not relevant function.
} catch (Exception e) {
str = e.toString();
e.printStackTrace();
}
/*
* Write the HTML to the response
*/
out.println("<html>");
out.println("<head>");
out.println("<title> this is your answers</title>");
out.println("</head>");
out.println("<body>");
if(str != ""){
out.println(str);
}
else{
for(int i = 0;i<=40;i++){
out.println(list.get(i));
out.println("<br>");
}
}
out.println("<a href='form.html'>"+"Click here to go back to input page "+"</a>");
out.println("</body>");
out.println("</html>");
out.close();
}
public void destroy() {
}
}
我的web.xml
代码:
<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<servlet>
<servlet-name>AzpanaServlet</servlet-name>
<servlet-class>com.example.AzpanaServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>AzpanaServlet</servlet-name>
<url-pattern>/AzpanaServlet</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>/form.html</welcome-file>
</welcome-file-list>
</web-app>
我的form.html
代码:
<html>
<head>
<title>Zeev's Project</title>
</head>
<body>
<h1>Just Enter String</h1>
<form method="POST" action="AzpanaServlet">
<label for="name">Enter String</label>
<input type="text" id="name" name="name"/><br><br>
<input type="submit" value="Submit Form"/>
<input type="reset" value="Reset Form"/>
</form>
</body>
</html>
文件夹的层次结构如下:
The hierarchy of the Folder is following:
ROOT[
WEB-INF[
web.xml
classes[
com[
example[
AzpanaServlet.class
AzpanaServlet$oneChar.class
]
]
]
lib[
AzpanaServlet.java
]
]
META-INF[
MANIFEST.MF
]
form.html
]
推荐答案
看看你的 IDE 控制台或你的 tomcat 日志,你的 web 应用程序是否成功启动过?
它可能由于某种原因没有启动.
Have a look at your IDE console or your tomcat log, did your web application ever started successfully?
It might didn't start for some reason.
这篇关于简单的 servlet 项目(HTTP 状态 404 错误)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!