Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The problem (and its solution) is as follows:</p> <p>You create a request scope bean <code>user</code> but once the page is loaded the request is finished and gone - no wonder it is <code>null</code> in the next request which is completely unrelated to this one. What you probably wanted to do is the following:</p> <p>1) Remove the <code>&lt;jsp:useBean ...&gt;</code> from your jsp page completely so it will look as follows:</p> <pre><code>&lt;%@ page contentType="text/html;charset=UTF-8" language="java" %&gt; &lt;%@page import="com.hermes.data.RateCode_" %&gt; &lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"&gt; &lt;html&gt; &lt;head&gt;&lt;title&gt;Rate Code&lt;/title&gt;&lt;/head&gt; &lt;body&gt; &lt;form id="f_rateCode" action="/forwarder.jsp" method="post"&gt; &lt;table align="center" border="1" cellspacing="0"&gt; &lt;tr&gt; &lt;td colspan="2" align="center" class="header"&gt;Rate Code Administrations&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td align="right" style="border-style: solid;"&gt;Rate Code:&lt;/td&gt; &lt;td align="left" style="border-style: solid;"&gt;&lt;input type="text" id="code" name="code" value="" size="10" maxlength="32" style="width: 100px"/&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td align="right" style="border-style: solid;"&gt;Rate Description:&lt;/td&gt; &lt;td align="left" style="border-style: solid;"&gt;&lt;input type="text" id="description" name="description" value="" maxlength="128" size="40"&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;input type="submit" value="ok"/&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>2) Your form now redirects to another jsp, the forwarder. It looks like follows:</p> <pre><code>&lt;%@ page contentType="text/html;charset=UTF-8" language="java" %&gt; &lt;jsp:useBean id="user" class="com.hermes.data.RateCode_" scope="request"/&gt; &lt;jsp:setProperty name="user" property="*" /&gt; &lt;jsp:forward page="/ratePromoCodes" /&gt; </code></pre> <p>What this does: it creates the bean in request scope - <em>the request which submitted the form</em>. Then it populates the bean properties with the data from the form and finally it forwards (<em>IN SAME REQUEST, HERE IS THE POINT</em>) to the servlet which does some job.</p> <p>3) Finally do something in your servlet, I did this for testing purposes:</p> <pre><code>public class TestServlet extends javax.servlet.http.HttpServlet { protected void doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException { RateCode_ code = (RateCode_) request.getAttribute("user"); System.out.println(code); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload