Java, .NET, PHP, PYTHON, ANGULAR, ML, Data Science, Testing, CI Tutorials in Easy Languages.

"Best Software Training, Internship, Project Development center of Indore India, Helpline 780506-3968"

 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;


@Controller

public class AdditionExample {


@RequestMapping("/add")

public String loadForm()

{

return "add";

}

@RequestMapping("/addlogic")

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<>();

ht.put("num1",a);

ht.put("num2",b);

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"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form action="addlogic" method="post">
<input type="text" placeholder="Enter first number" name="txtnum1" />
<br><br>
<input type="text" placeholder="Enter second number" name="txtnum2" />
<br><br>
<input type="submit" name="btnsubmit" value="Add" />
</form>

${key}
</body>
</html>





Post a Comment

If you have any doubt in programming or join online classes then you can contact us by comment .

Previous Post Next Post