Question
Having a hard time converting this. Could someone help? Modify the Currency Converter application so it uses the MVC architecture. In particular, Requests should always
Having a hard time converting this. Could someone help?
Modify the Currency Converter application so it uses the MVC architecture. In particular,
Requests should always be sent to controllers, not directly to views.
Servlets do not generate HTML content.
No Java code in JSP, i.e. no JSP expression (<%= %>), JSP scriptlet (<% %>), or JSP declaration (<%! %>).
Current Java Form
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet("/CurrencyConverter")
public class CurrencyConverter extends HttpServlet {
private static final long serialVersionUID = 1L;
public CurrencyConverter()
{
super();
}
public void init( ServletConfig config ) throws ServletException
{
super.init( config );
Map
try
{
// read file
Scanner in;
in = new Scanner( new File(
getServletContext().getRealPath( "/WEB-INF/rates.txt" ) ) );
while( in.hasNextLine() )
{
String line = in.nextLine();
String tokens[] = line.split( " " );
data.put( tokens[0], Double.valueOf( tokens[1] ) );
}
in.close();
}
catch( FileNotFoundException e )
{
throw new ServletException( e );
}
getServletContext().setAttribute( "data", data );
}
@SuppressWarnings("unchecked")
protected void doGet( HttpServletRequest request,
HttpServletResponse response ) throws ServletException, IOException
{
Map
.getAttribute( "data" );
response.setContentType( "text/html" );
PrintWriter out = response.getWriter();
out.println(
"
out.println( "
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started