我顺便把源码也贴上吧,共有两个jsp页面,一个为form的填写npQuery.jsp,当checkbox
被选择时,参数值为“测试”。
另一个是返回结果QueryResult.jsp:显示checkbox的参数值和bean中的sample值
用到的bean:newspaperquerytest.npQueryBean,极简单,
只不过存了一个属性sample,赋初值为“厨师”
“测试”和“厨师”总不能同时显现。总有一个是??
----------------------------------------------------
npQuery.jsp:
--------------------------------------------------------
<HTML>
<HEAD>
<%@ page language="java" contentType="text/html;charset=GB2312" %>
<jsp:useBean id="npQueryBeanId" scope="session" class="newspaperquerytest.npQueryBean" />
<TITLE>
条件
</TITLE>
</HEAD>
<BODY>
<BR>
<FORM action="QueryResult.jsp" method="post">
<BR>输入条件: <BR>
<BR><input type="checkbox" name="test" value="测试">
条件一
<select name="test1">
<option value="1" selected>a</option>
<option value="2">b</option>
</select>
<BR>
<BR><BR>
<INPUT TYPE="SUBMIT" NAME="Submit" VALUE=" ">
<INPUT TYPE="RESET" VALUE="">
<BR>
</FORM>
</BODY>
</HTML>
-----------------------------------------------------
QueryResult.jsp:
-----------------------------------------------------
<HTML>
<HEAD>
<%@ page language="java" contentType="text/html;charset=GB2312" %>
<jsp:useBean id="npQueryBeanId" scope="session" class="newspaperquerytest.npQueryBean" />
<TITLE>
查询条件
</TITLE>
</HEAD>
<BODY>
<H1>
<%
String test=new String();
test=request.getParameter("test");
out.println("参数:"+test);
test=npQueryBeanId.getSample();
out.println(";值:"+test);
%>
</H1>
</BODY>
</HTML>
--------------------------------------------------------
newspaperquerytest.npQueryBean:
--------------------------------------------------------
package newspaperquerytest;
public class npQueryBean {
private String sample = "厨师";
/**Access sample property*/
public String getSample() {
return sample;
}
/**Access sample property*/
public void setSample(String newValue) {
if (newValue!=null) {
sample = newValue;
}
}
}