单击我的表单上的提交按钮会生成一个保存对话框(要求我保存应该从 POST 调用运行的 .class 文件),而不是表单部分填写的新页面。
如上所述,我正在尝试将 Tomcat 7.0.40 与名为 Demonstration 的 Web 应用程序一起使用。我一直在 Eclipse 中编写非常简单的页面,然后编译它们并为 Tomcat 设置我自己的 .war 文件。经过多次尝试后,这并没有奏效,所以我让 Eclipse 为我构建 .war 文件。仍然没有工作。
这是我认为相关的代码。
运行的第一个文件是存储为 webapps\Demonstration\index.html 的 HTML
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="SurveyMark.css">
<meta charset="ISO-8859-1">
<title>SurveyMark - Input Job</title>
</head>
<body>
<form id="job_input_form" action="JobMade" method=POST>
<h1><img id="logo" alt="TJH Logo" src="logo_small.jpg" align="middle"><b> -
SurveyMark - Input Job INDEX.HTML</b></h1>
<div id="job_div" style="width:250px;float:left">
<h3>Job Details</h3>
<label for="job_number">Job Number</label>
<input type="text" name="job_number" id="job_number">
<label for="addendum">Addendum</label>
<input type="text" name="addendum" id="addendum">
<label for="development_name">Development Name</label>
<input type="text" name="development_name" id="development_name">
<label for="job_type">Job Type</label>
<input type="text" name="job_type" id="job_type">
<label for="date_recieved">Date Recieved</label>
<input type="text" name="date_recieved" id="date_recieved">
</div>
<div id="job_location_div" style="width:250px;float:left">
<h3>Job Location</h3>
<label for="unit_number">Unit Number</label>
<input type="text" name="unit_number" id="unit_number">
<div id="legal_street_number_div" style="width:120px;float:left">
........
........Lots more fields all on the same page, displaying properly
</div>
<input type="submit" value="Add Job">
</form>
</body>
</html>
它尝试 POST 到以下文件 \webapps\Demonstration\WEB-INF\classes\Demonstration\JobMade.class (从这个 JobMade.java 文件编译)
package Demonstration;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
@WebServlet("/JobMade")
public class JobMade extends HttpServlet {
/**
*
*/
private static final long serialVersionUID = 1L;
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
//String title = "Job Data that has Been Entered";
out.println("<!DOCTYPE html>\n" +
"<html>\n" +
"<head>\n" +
"<link rel=\"stylesheet\" type=\"text/css\" href=\"SurveyMark.css\">" +
"<meta charset=\"ISO-8859-1\">" +
"<title>SurveyMark - Input Job JOBMADE FILE</title>" +
"</head>" +
"<body>" +
"<form id=\"job_input_form\" action=\"AddedJob.html\" method=\"post\">" +
"<input type=\"submit\" value=\"Add Job\">" +
"<h1><img id=\"logo\" alt=\"TJH Logo\" src=\"logo_small.jpg\" align=\"middle\"> - " +
"SurveyMark - Added Job as Follows</h1>");
@SuppressWarnings("rawtypes")
Enumeration paramNames = request.getParameterNames();
while (paramNames.hasMoreElements()) {
String paramName = (String)paramNames.nextElement();
out.println("<TR><TD>" + paramName + "\n<TD>");
String[] paramValues = request.getParameterValues(paramName);
if (paramValues.length == 1) {
String paramValue = paramValues[0];
if (paramValue.length() == 0)
out.print("<I>No Value</I>");
else
out.print(paramValue);
} else {
out.println("<UL>");
for(int i = 0; i < paramValues.length; i++) {
out.println("<LI>" + paramValues[i]);
}
out.println("</UL>");
}
}
out.println("</TABLE>\n</BODY></HTML");
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
}
}
我已经查看了 catalina 日志文件,找不到任何不愉快的地方,但如果有什么具体的东西可以帮助我全神贯注。
这是存储在 WEB-INF 目录下的简短但重要的 web.xml 文件。
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web- app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>Demonstration</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>
预先感谢您的帮助。