所以我的.jsp文件中有这段代码
<table border="0" style="width:400px;">
<form class="Credentials" action="SellerServlet" method="post">
<tr style="height: 40px">method
#User name
<td style="width: 20%; text-align: right;">
<label for="Name"><b>Name:</b></label>
</td>
<td>
<input type="text" id="Name" name="Name" required>
</td>
</tr>
#Surname
<tr style="height: 40px">
<td style="width: 20%; text-align: right;" >
<label for="surname"><b>Surname:</b></label>
</td>
<td>
<input type="text" id="Surname" name="Surname" required>
</td>
</tr>
#Username
<tr style="height: 40px">
<td style="width: 20%; text-align: right;">
<label for="username"><b>Username:</b></label>
</td>
<td>
<input type="text" id="username" name="user" required>
</td>
</tr>
<tr style="height: 40px">
<td style="width: 20%; text-align: right;" >
<label for="password"><b>Password:</b></label>
</td>
<td>
<input type="password" id="password" name="pass" required>
</td>
</tr>
#User Type
<tr style="height: 40px">
<td style="width: 20%; text-align: right;" >
<label for="type"><b>Type:</b></label>
</td>
<td>
<input type="text" id="type" placeholder="Client" readonly>
</td>
</tr>
#User Program
<tr style="height: 40px">
<td style="width: 20%; text-align: right;" >
<label for="program"><b>Program:</b></label>
</td>
<td>
<select style="width: 150px" id="program" name="program" >
<option value="" selected disabled hidden>Επιλέξτε πρόγραμμα</option>
<option>asdfs</option>
<option>asdfas</option>
<option>asfdas</option>
</select>
</td>
</tr>
#Submit Button
<tr style="height: 100px;">
<td colspan="2" style="width: 50%">
<center>
<button type="submit" name="Register" >Register</button>
</center>
</td>
</tr>
</form>
</table>
而且我的servlet代码是
@WebServlet(name = "SellerServlet" , urlPatterns = {"/SellerServlet"})
public class SellerServlet extends HttpServlet {
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
String registerButton = request.getParameter("register");
if(registerButton!=null){
//request.getRequestDispatcher("/index.jsp").forward(request, response);
String Username=request.getParameter("user");
String Password=request.getParameter("pass");
System.out.println(Username+Password);
Seller CreateClient= new Seller();
CreateClient.CreateClientAccount(Username,Password);
}
}
}
这里的servlet应该做的是将2个值(用户和传递)传递给Seller类的对象,以便以后对它们进行某些操作,我没有包括以下部分,因为它起作用了,它只是获取了值两者都为零,我现在已经摔了两个小时,试图找出原因
如果需要:使用Java 14和tomcat 9