gpt4 book ai didi

java - Netbeans 结构问题

转载 作者:行者123 更新时间:2023-11-29 22:16:02 26 4
gpt4 key购买 nike

所以我在 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>");
}}

最佳答案

先从最重要的事情开始...先下课...

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

有关更多信息.. 请访问 Javadocs... The try Block

关于java - Netbeans 结构问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31199693/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com