title: Convert Temperature through jsp
body: <p>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</p>
  
  <ol>
  <li><p>An html form that contains a form to input a temperature number and 2 radio buttons to decide if you want Celsius or Fahrenheit.  </p></li>
  <li><p>A jsp page that takes the value of that form and does the math to convert the temperature. </p></li>
  <li><p>A jsp page that throws an error if the user enters invalid characters in the form. </p></li>
  </ol>
  
  <p>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. </p>
  
  <p>Page 1:</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
      &lt;head&gt;
          &lt;title&gt;&lt;/title&gt;
          &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
  
      &lt;/head&gt;
  
      &lt;body&gt;
          &lt;script type="text/javascript"&gt;
              function check(){
                  document.getElementByValue("fahr").checked=true
  
              }
              function check2(){
                  document.getElementByValue("cel").checked=true
              }
  
              // --&gt;
          &lt;/script&gt;
  
          &lt;form name="Temperature Converter" method="get" action="convert.jsp"&gt;
              &lt;h2 style="font-family:arial;color:red"&gt;Temperature Calculator&lt;/h2&gt;
  
              &lt;table border="1"&gt;
                  &lt;tbody&gt;
                      &lt;tr&gt;
                          &lt;td&gt;Enter a temperature in number form:&lt;/td&gt;
                          &lt;td&gt;
                              &lt;input type="text" name="fTemp" id="fTemp"  /&gt;
                          &lt;/td&gt;
                          &lt;td&gt;
                              &lt;input type="radio" name="temp" value="cel" onclick="check2();return false"&gt;Convert to Celsius
                              &lt;br&gt;
                              &lt;input type="radio" name="temp" value="fahr" onclick="check();return false"&gt;Convert to Fahrenheit
                          &lt;/td&gt;
                      &lt;/tr&gt;
                      &lt;tr&gt;
                          &lt;td&gt;&lt;input type="submit" value="Convert!"&gt;
  
                          &lt;/td&gt;
                      &lt;/tr&gt;
                  &lt;/tbody&gt;
              &lt;/table&gt;
          &lt;/form&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Page 2: This is where I feel like it's a mess.</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;%@page contentType="text/html"%&gt;
  &lt;%@page import="java.sql.*" %&gt;
  &lt;%@page session="true"%&gt;
  &lt;%!
      String inp = null;
      int temperature = 0;
          int c = 0;
          int f = 0;
  
  %&gt; 
  &lt;%
      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;
      }
  %&gt;
  &lt;!DOCTYPE HTML&gt;
  &lt;html&gt;
      &lt;head&gt;
          &lt;title&gt;First jsp Page&lt;/title&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;p&gt;The temperature is &lt;%= c %&gt;&lt;/p&gt;
                  &lt;p&gt;The temperature is &lt;%= f %&gt;&lt;/p&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Thank you very much for any advice/direction and I apologize for the long message.</p>