Netbeans结构问题

时间:2015-07-03 06:11:24

标签: java mysql netbeans

所以我在Netbeans和SQL中创建了一个java项目,这是项目创作的初学者。我在homepage.html中创建了一个表单,并在名为homepage.java的源文件下创建了一个文件。请注意,homepage.html中表单中的操作是homepage.java

现在,我想在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>");
        }}

1 个答案:

答案 0 :(得分:0)

首先从第一件事开始......先关闭你的课......

然后在catch(){ }块之后添加try{ }块。因为try{ }块始终包含至少一个catch() { }finally{ }块。

更多..转到Javadocs ...... The try Block