JSP表单将值传递给使用post

时间:2015-10-14 18:50:03

标签: javascript java jsp servlets

好的,我试图从页面上的表单传递值。

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>

我将这些值传递给confirm.jsp。我在这做错了什么?我是否需要在web.xml中设置servlet。互联网上的所有内容都指向我这个代码,但到目前为止,我得到的只是空值。

任何帮助都会很棒

2 个答案:

答案 0 :(得分:1)

相反

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

使用

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

无需在web.xml文件中进行配置。由于您在form标记中撰写了action="confirm.jsp

答案 1 :(得分:0)

<强> 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>
那对我来说太好了!!