I've searched for a good 2 hours now but obviously I'm not searching in the right place. I am trying to create a temperature converter calculator.It is three pages
An html form that contains a form to input a temperature number and 2 radio buttons to decide if you want Celsius or Fahrenheit.
A jsp page that takes the value of that form and does the math to convert the temperature.
A jsp page that throws an error if the user enters invalid characters in the form.
I am having difficulty on making my jsp page convert the number and redirect the user to another page displaying the result. When I enter a number and press the submit button I am taken to my code for the jsp page. This is an assignment for a class if you are wondering. I am ready to flip tables and need help. My code is below.
Page 1:
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<script type="text/javascript">
function check(){
document.getElementByValue("fahr").checked=true
}
function check2(){
document.getElementByValue("cel").checked=true
}
// -->
</script>
<form name="Temperature Converter" method="get" action="convert.jsp">
<h2 style="font-family:arial;color:red">Temperature Calculator</h2>
<table border="1">
<tbody>
<tr>
<td>Enter a temperature in number form:</td>
<td>
<input type="text" name="fTemp" id="fTemp" />
</td>
<td>
<input type="radio" name="temp" value="cel" onclick="check2();return false">Convert to Celsius
<br>
<input type="radio" name="temp" value="fahr" onclick="check();return false">Convert to Fahrenheit
</td>
</tr>
<tr>
<td><input type="submit" value="Convert!">
</td>
</tr>
</tbody>
</table>
</form>
</body>
</html>
Page 2: This is where I feel like it's a mess.
<%@page contentType="text/html"%>
<%@page import="java.sql.*" %>
<%@page session="true"%>
<%!
String inp = null;
int temperature = 0;
int c = 0;
int f = 0;
%>
<%
inp = request.getParameter("fTemp");
if (inp == null || inp.equals("") )
{
response.sendRedirect("errorMsg.jsp?msg=You are missing values.");
return;
}
try
{
if (request.getParameter("cel") = checked)
{
f = Integer.parseInt(inp);
c = (f - 32) * (5.0 / 9.0);
}else{
c = Integer.parseInt(inp);
c = parseFloat(request.getParameter('inp').value);
f = (c * (9.0 / 5.0)) + 32.0;
}
catch (Exception e)
{
response.sendRedirect("errorMsg.jsp?msg=Invalid numbers entered.");
return;
}
%>
<!DOCTYPE HTML>
<html>
<head>
<title>First jsp Page</title>
</head>
<body>
<p>The temperature is <%= c %></p>
<p>The temperature is <%= f %></p>
</body>
</html>
Thank you very much for any advice/direction and I apologize for the long message.