0
所以我在Netbeans和SQL中創建了一個java項目,有點初學者來創建項目。我在homepage.html
中創建了一個表單,並在名爲homepage.java
的源文件下創建了一個文件。請注意,在homepage.html
中的表單中的操作是homepage.java
。Netbeans結構問題
現在,我想在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>");
}}
所以什麼問題 – CoderNeji
的公共無效確認部分不工作,我不知道爲什麼。有什麼我失蹤的東西?不應該在表格上打印任何內容。它會在processrequest部分要求時輸出密碼。 – Megatron