How to use HashTable in Spring MVC Web Application



Code of  Controller Class:-

package bao;

import java.util.*;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;

import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.servlet.ModelAndView;


public class AdditionExample {


public String loadForm()


return "add";



public ModelAndView addLogic(HttpServletRequest request, HttpServletResponse response)


int a = Integer.parseInt(request.getParameter("txtnum1"));

int b = Integer.parseInt(request.getParameter("txtnum2"));

Hashtable<String, Integer> ht = new Hashtable<>();



Set<Map.Entry<String,Integer>> se = ht.entrySet();

int sum=0;

for(Map.Entry<String, Integer> me:se)


sum = sum+me.getValue();


int c= sum;

return new ModelAndView("add","key","result is "+c);



Code of View Page:-

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<form action="addlogic" method="post">
<input type="text" placeholder="Enter first number" name="txtnum1" />
<input type="text" placeholder="Enter second number" name="txtnum2" />
<input type="submit" name="btnsubmit" value="Add" />


Post a Comment


POST Answer of Questions and ASK to Doubt

Post a Comment (0)