嗨,我有这个网络应用程序,应该计算每个输入中编码的卡的总和。它很成功,但数据不会持久。这是我的代码。
控制器:
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String BusName = "";
String PlateNumber = "";
String DriverAssigned = "";
try{
BusName = request.getParameter("busName");
PlateNumber = request.getParameter("plateNo");
DriverAssigned = request.getParameter("driverAssigned");
String firstString = PlateNumber.substring(0, 2);
String secondString = PlateNumber.substring(3, 5);
if (firstString.matches(".*[A-Z].*") && secondString.matches(".*\\d.*")){
CalculatorBean beanCalc = BeanFactory.getInstance(BusName, PlateNumber, DriverAssigned);
HttpSession session = request.getSession();
session.setAttribute("deJesusBean", beanCalc);
RequestDispatcher dispatcher = request.getRequestDispatcher("displayresult.jsp");
dispatcher.forward(request, response);
我的逻辑模型:
public void compute(){
char x = plateNo.charAt(5);
if (x == '1' || x == '2'){
dayOfCoding = "Monday";
mondayCoding = mondayCoding + 1;
}
else if (x == '3' || x == '4'){
dayOfCoding = "Tuesday";
tuesdayCoding = tuesdayCoding + 1;
}
else if (x == '5' || x == '6'){
dayOfCoding = "Wednesday";
wednesdayCoding = wednesdayCoding + 1;
}
else if (x == '7' || x == '8'){
dayOfCoding = "Thursday";
thursdayCoding = thursdayCoding + 1;
}
else if (x == '9' || x == '0'){
dayOfCoding = "Friday";
fridayCoding = fridayCoding + 1;
}
}
我用它来显示它
${deJesusBean.mondayCoding}
答案 0 :(得分:-1)
您需要删除会话或使会话无效,请尝试以下代码
HttpSession session = request.getSession();
if(session.getAttribute("deJesusBean") != null){
session.removeAttribute("deJesusBean");
session.setAttribute("deJesusBean", beanCalc);
}