Как сравнить в hashmap
у меня есть html-форма бронирования номера , если номер и этаж уже забронированы, мне нужно отправить ее errorpage.jsp, я попробовал это с помощью treemap, но я не знаю, как сравнить значения getparam и Значения карты, пожалуйста, сообщите синтаксис
Что я уже пробовал:
package com; import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.io.Reader; import java.util.HashMap; import java.util.TreeMap; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; /** * Servlet implementation class SelectedRoomServlet */ //@WebServlet("/SelectedRoomServlet") public class SelectedRoomServlet extends HttpServlet { private static final long serialVersionUID = 1L; /** * @see HttpServlet#HttpServlet() *//* public SelectedRoomServlet() { super(); // TODO Auto-generated constructor stub } *//** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) *//* protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub } *//** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String name = request.getParameter("textnames"); String empid = request.getParameter("empid"); String emailid = request.getParameter("emailid"); String project = request.getParameter("project"); String floor = request.getParameter("floor"); //String floor = request.getParameter("FLOOR"); String rooms = request.getParameter("rooms"); HttpSession sess = request.getSession(); sess.setAttribute("name", name); sess.setAttribute("empid", empid); sess.setAttribute("emailid", emailid); sess.setAttribute("project", project); sess.setAttribute("floor", floor); sess.setAttribute("rooms", rooms); /*//String line = null; String ln =""; String Str ="E://ConferenceRoomBooking//text.txt"; File file = new File(Str); FileWriter filewriter = new FileWriter(file,true); String[] values = ln.split("!"); for (String str : values) { String[] element = str.split(","); if(rooms.equals(element[0])&&floor.equals(element[1])) { response.sendRedirect("errorpage.jsp"); } else { filewriter.write("name:"+name +"empid:"+empid+"room:"+rooms +"floor:" +floor); if(rooms.equals(rooms)&&floor.equals(floor)) response.sendRedirect("Selectedroom.jsp"); } filewriter.close(); */ TreeMap<String, String> map = new TreeMap<String, String>(); map.put(rooms, floor); if(map.containsKey(rooms)&&map.containsValue(floor)){ response.sendRedirect("errorpage.jsp"); } else { response.sendRedirect("Selectedroom.jsp"); } } }