Я пытаюсь получить входные данные от html, но все входные данные в моем сервлете считаются нулевыми, однако каким-то образом код все еще проталкивает мой сервлет и корректно обновляется, но нулевые значения позволяют любому пользователю изменять пароли .
Все содержимое работает как задумано, за исключением этих нулей.
html
<html>
<head>
<link rel="stylesheet" href="style.css" />
<title>Employee Update</title>
</head>
<body>
<h1>Update My Account</h1>
<form method = "post" action="/BaldwinReburst/updateemployee" >
<div id = "message"> </div>
<div id = "menu" class ="form-group">
<label for="Username">Username:</label> <input type="text"
id="Username" class="form-control" name="Username" required />
<label for="firstname">FirstName:</label> <input type="text"
id="firstname" class="form-control" name="firstname" required />
<label for="lastname">Lastname:</label> <input type="text"
id="lastname" class="form-control" name="lastname" required />
<label for="passwordcurrent">current password:</label> <input type="text"
id="passwordcurrent" class="form-control" name="passwordcurrent" required />
<label for="passwordnew">New Password:</label> <input type="text"
id="passwordnew" class="form-control" name="passwordnew" required />
<label for="passwordCon">New Password Confirm:</label> <input type="text"
id="passwordCon" class="form-control" name="passwordCon" required />
<input id = "submit" type="submit" >
</div>
</form>
<a href="EmployeeAccount.html"><button>Back to Menu</button></a>
<script src="./Scripts/UpdateAccount.js"></script>
</body>
</html>
Java Сервлет: Все значения, когда я получаю параметры, основанные на моем из печати вернись как ноль пытался в течение нескольких дней, чтобы исправить это
package com.BaldwinReburst.Servlet;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import com.google.gson.Gson;
import com.Remburstment.service.EmployeeService;
/**
* Servlet implementation class That updates the currentaccount
*/
public class UpdateEmployee extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public UpdateEmployee() {
super();
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
EmployeeService empSer = new EmployeeService();
HttpSession session = request.getSession();
session.setAttribute("message", "");
String old = session.getAttribute("username").toString();
String username = request.getParameter("Username");
String first = request.getParameter("firstname");
String last = request.getParameter("lastname");
String passwordCurrent =request.getParameter("passwordcurrent");
String passwordNew =request.getParameter("passwordnew");
String passwordCon =request.getParameter("passwordCon");
System.out.println("old: " +old);
System.out.println("username: " +username);
System.out.println("first: " +first);
System.out.println("last: " +last);
System.out.println("passwordCurrent: " +passwordCurrent);
System.out.println("passwordNew: " +passwordNew);
System.out.println("passwordCon: " +passwordCon);
String newUser = null;
String newPassword = null;
String newFirst = null;
String newLast = null;
//check password is correct
if(passwordCurrent.equals(empSer.getEmp(old).getPassword()) && passwordCurrent != null && empSer.getEmp(old).getPassword() != null){
//Checks if Username Remains the same
if(empSer.checkEmployee(username)==true && old.equals(username)) {
newUser = old;
}
else if(empSer.checkEmployee(username)==false && old.equals(username)==false) {
newUser = username;
session.setAttribute("username", username);
}
//checks for password
if(passwordNew.equals(passwordCon)) {
newPassword = passwordNew;
}
//checks Firstname
if(first.equals(empSer.getEmp(old).getFirstName())) {
newFirst = empSer.getEmp(old).getFirstName();
}
else if(first.equals(empSer.getEmp(old).getFirstName())== false) {
newFirst = first;
}
//checks Lastname
if(first.equals(empSer.getEmp(old).getFirstName())) {
newLast = empSer.getEmp(old).getLastName();
}
else if(first.equals(empSer.getEmp(old).getFirstName())== false) {
newLast = last;
}
if(session.getAttribute("message").toString() == "") {
empSer.updateAccount(old, newUser, newPassword, newFirst, newLast);
session.setAttribute("message", "UsernameUpdated");
String message = session.getAttribute("message").toString();
response.setContentType("application/json");
Gson gson = new Gson();
response.getWriter().write(gson.toJson(message));
}
String message = session.getAttribute("message").toString();
response.setContentType("application/json");
Gson gson = new Gson();
response.getWriter().write(gson.toJson(message));
response.sendRedirect("http://localhost:8080/BaldwinReburst/AccountEmp/EmployeeAccount.html");
}
else{
session.setAttribute("message", "Improper input");
String message = session.getAttribute("message").toString();
response.setContentType("application/json");
Gson gson = new Gson();
response.getWriter().write(gson.toJson(message));
response.sendRedirect("http://localhost:8080/BaldwinReburst/AccountEmp/EmployeeAccount.html");
}
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}
}