简体   繁体   中英

JSP form passing values to using post

OK so I'm trying to pass values from a form on a page.

contact.jsp

<form id="myform" name="myform" method="post" action="confirm.jsp">
                   <p> Cell Line: <input type="text"  name="cell" />
                   <p> Tissue Source<input type="text"  name="source" />
                   <p> Temperature: <input type="text"  name="temp" />
                   <p> Run-Time: <input type='text'   name='run' />
                  <input type="submit" value="Request!"onclick="window.location.href='confirm.jsp'" />
/form>

confirm.jsp

<div class="controls">
<p><label>Cell Line:</label> <% String cell=request.getParameter("cell"); out.println(cell); %> </p>
<p><label>Tissue Source:</label> <% String source=request.getParameter("source"); out.println(source); %> </p>
<p><label>Temperature:</label> <% String temp=request.getParameter("temp"); out.println(temp); %> </p>
<p><label>Run-Time</label> <% String run=request.getParameter("first"); out.println(run); %> </p>
<p class="help-block"></p>
</div>

I'm passing these values to confirm.jsp. what have I done wrong here? Do i need to set a servlet in my web.xml. everything on the inter webs points me to this code, but to date all i get is null values.

Any help would be great

Instead

 <input type="submit" value="Request!"onclick="window.location.href='confirm.jsp'" />

Use

<input type="submit" value="Request!"/>

There is no need of configuring in web.xml file. Since in form tag you wrote action="confirm.jsp .

contact.jsp

<form id="myform" name="myform" method="post" action="confirm.jsp">
                   <p> Cell Line: <input type="text"  name="cell" />
                   <p> Tissue Source<input type="text"  name="source" />
                   <p> Temperature: <input type="text"  name="temp" />
                   <p> Run-Time: <input type='text'   name='run' />
                  <input type="submit" value="Request!" />
/form>

confirm.jsp

<div class="controls">
<p><label>Cell Line:</label> <% String cell=request.getParameter("cell"); out.println(cell); %> </p>
<p><label>Tissue Source:</label> <% String source=request.getParameter("source"); out.println(source); %> </p>
<p><label>Temperature:</label> <% String temp=request.getParameter("temp"); out.println(temp); %> </p>
<p><label>Run-Time</label> <% String run=request.getParameter("first"); out.println(run); %> </p>
<p class="help-block"></p>
</div>

that woks for me so fine !!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM