2015-07-03 145 views
0

所以我在Netbeans和SQL中創建了一個java項目,有點初學者來創建項目。我在homepage.html中創建了一個表單,並在名爲homepage.java的源文件下創建了一個文件。請注意,在homepage.html中的表單中的操作是homepage.javaNetbeans結構問題

現在,我想在homepage.java中創建其他文件來操縱我讓用戶輸入的信息,但無法這樣做。 以下是我在homepage.java

package Introduction; 
package Introduction; 
import java.io.IOException; 
import java.io.PrintWriter; 
import javax.servlet.ServletException; 
import javax.servlet.http.HttpServlet; 
import javax.servlet.http.HttpServletRequest; 
import javax.servlet.http.HttpServletResponse; 


public class Homepage extends HttpServlet { 

    /** 
    * Processes requests for both HTTP <code>GET</code> and 
     <code>POST</code> 
    * methods. 
    * 
    * @param request servlet request 
    * @param response servlet response 
    * @throws ServletException if a servlet-specific error occurs 
    * @throws IOException if an I/O error occurs 
    */ 
    public void confirm(){ 

     try (PrintWriter out = response.getWriter()) 
      out.println{"<h1>" + ("Anything") + "</h1>";} 
    } 



    protected void processRequest(HttpServletRequest 
    request,HttpServletResponse response) 
      throws ServletException, IOException { 
     response.setContentType("text/html;charset=UTF-8"); 
     String part = request.getParameter("part"); 
     String product = request.getParameter("product"); 
     String type = request.getParameter("type"); 
     String use = request.getParameter("use"); 
     String password = request.getParameter("password"); 


     try (PrintWriter out = response.getWriter()) { 

      out.println("<!DOCTYPE html>"); 
      out.println("<html>"); 
      out.println("<head>"); 
      out.println("<title>Servlet Homepage</title>");    
      out.println("</head>"); 
      out.println("<body>"); 
      out.println("<h1>Part " + password + "</h1>"); 
      out.println("</body>"); 
      out.println("</html>"); 
     }} 
+0

所以什麼問題 – CoderNeji

+0

的公共無效確認部分不工作,我不知道爲什麼。有什麼我失蹤的東西?不應該在表格上打印任何內容。它會在processrequest部分要求時輸出密碼。 – Megatron

回答

0

與第一件事開始第一...關閉你的類第一...

然後try{ }塊後添加catch(){ }塊。因爲try{ }塊總是至少有一個catch() { }finally{ }塊。

更多..去的Javadoc ... The try Block