title: How do you print a variable in a .jsp file that is from a Java class?
body: <p>I have a .jsp file that should tell the user the result of their exam.</p>
  
  <p>This is the WebController.java class that works out what a person gave as their answer and then adds either 0 or 1 depending on if their answer is wrong or right.</p>
  
  <pre><code>@RequestMapping(value = "/results", method = RequestMethod.POST)
      public String results(Model model, HttpSession session, HttpServletRequest request,
              HttpServletResponse response){
  
              String radio = request.getParameter("radios1");
  
              request.setAttribute("total", total);
              model.addAttribute("total", total);
  
              if (radio.equals("int")){
                  total = total + 0;
              }
              else if (radio.equals("Enum")){
                  total = total + 0;
              }
              else if (radio.equals("integer")){
                  total = total + 0;
              }
              else if (radio.equals("Integer")){
                  total = total + 1;
              }
  
              return "results";
  }
  </code></pre>
  
  <p>I would like to print the "total" variable onto the jsp page so it displays in the browser.
  So the idea is the user will instantly be able to see what they got in their test.</p>
  
  <p>Also can this work the same way in reverse? e.g. in the code above can the java class get the parameter "radios1" which is located inside a form in a jsp class?</p>
  
  <pre><code>&lt;p&gt;Good day &lt;%= session.getAttribute("uname") %&gt; &lt;/p&gt;
  &lt;p&gt;For question 1 you chose &lt;%= session.getAttribute("q1") %&gt; &lt;/p&gt;
  &lt;p&gt;For question 2 you chose &lt;%= session.getAttribute("q2") %&gt; &lt;/p&gt;
  &lt;p&gt;For question 3 you chose &lt;%= session.getAttribute("q3") %&gt; &lt;/p&gt;
  &lt;p&gt;For question 4 you chose &lt;%= session.getAttribute("q4") %&gt; &lt;/p&gt;
  
  &lt;section&gt;
  
      &lt;p&gt;Total score: ${requestScope.total}&lt;/p&gt;
      &lt;p&gt;Total score: ${total}&lt;/p&gt;
  &lt;/section&gt;
  </code></pre>