2013-06-13 24 views
-1

單擊表單上的提交按鈕會產生一個保存對話框(要求我保存應該作爲調用運行的.class文件從POST),而不是一個新的頁面與表格部分填寫。在Ubuntu 12.04服務器和Eclipse EE上使用Tomcat 7:servlet不會運行類文件

如上所述,我正在嘗試將Tomcat 7.0.40與我的Web應用程序Demonstration結合使用。我一直在Eclipse中編寫相當簡單的頁面,然後編譯它們併爲Tomcat設置我自己的.war文件。這在許多次嘗試之後都不起作用,所以我讓Eclipse爲我構建.war文件。仍然沒有工作。

這是我認爲是相關的代碼段。

運行的第一個文件是這樣的HTML存儲爲web應用\演示\ index.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 \演示\ WEB-INF \類\演示\ 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 

    } 

} 

我在卡塔利娜日誌文件lloked,並不能找到任何麻煩,但如果有什麼具體的,這將有助於我所有的耳朵。

下面是存儲在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> 

非常感謝您的幫助。

+0

您沒有將該servlet映射到任何地方..?沒有在web.xml文件中,也沒有使用註釋... –

+0

@JanDoerrenhaus對不包括我的@WebServlet(「/ myServlet」)或@WebServlet(「/ JobMade」)抱歉我已經對這段代碼進行了許多修改,過去的24小時,並沒有使它反映了我認爲可能工作的許多變化之一。代碼被更新以反映我曾經在一個點上的映射,並得到相同的結果。歡呼聲,指出它。 –

+0

@JanDoerrenhaus你是對的,儘管我嘗試了一百多萬種方法來繪製它,但我顯然沒有嘗試正確的方法。如果您的評論是答案,我會爲您勾選,謝謝您指出我的錯誤。 –

回答

0

您沒有將該servlet映射到任何地方。無論是在web.xml文件中,還是使用註釋。

相關問題