<html:form > <table><tr>
<td >html:submit value = " 按日期查询 " onclick = "return check();"/></td>
<br></tr>
</table>
</html:form>
<html:form > <table><tr>
<td ><html:submit value = " 按ID查询 " onclick = "return check();"/></td>
<br></tr>
</table>
</html:form>
<td >html:submit value = " 按日期查询 " onclick = "return check();"/></td>
<br></tr>
</table>
</html:form>
<html:form > <table><tr>
<td ><html:submit value = " 按ID查询 " onclick = "return check();"/></td>
<br></tr>
</table>
</html:form>
就一个查询条件不一样,
<%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %>
<%@ taglib uri="/WEB-INF/struts-nested.tld" prefix="nested" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-template.tld" prefix="template" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ page contentType="text/html; charset=GBK" %>
<html:html>
<head>
<title>
UntitledJsp1
</title>
<script language="javascript" >
function Sua()
{
document.forms[0].method="post";
document.forms[0].action = "/action1.do";
document.forms[0].submit();
}
</script>
</head>
<body>
<h1>JBuilder Generated Struts JSP for ActionForm web13.ActionForm1</h1>
<p>
<html:form action="/action1.do" method="POST">
<a href='javaScript:Sua();'>aaa</a>
<html:reset value ="Reset"/>
</html:form>
</body>
</html:html>
<head></head>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
function getData(){
document.forms[0].submit();
}
</script>
<body>
<form id="form1" name="form1" method="get" action="http://xiayuanfeng.javaeye.com">
<input type="button" name="aa" onclick="getData();" value="提交">
</form>
</body>
</html>
var actForm = docuent.getElementById("");
找着Form对象
用actForm.submit();方法提交给对每个Form对应的Action
所需参数可用隐藏表单域
其中struts中的配置如下:
<action path="/apply"
parameter="method"
type="org.springframework.web.struts.DelegatingActionProxy">
<forward name="success" path="/delsucc.jsp" />
<forward name="error" path="/grantPower.jsp" />
</action>
spring的配置如下:
<bean name="/apply" class="action.Apply">
<property name="applyDAO">
<ref bean="messagesDao" />
</property>
<property name="userDAO">
<ref bean="userDaoImpl" />
</property>
</bean>
把2个文本框写到一个form中后台查询写sql语句时判断一下
给你看个好久以前做过的小例子
public List findPayoffByTerm(Payoff payoff){
StringBuffer sqlBuffer = new StringBuffer();
if(payoff.getPayoffState()==0){
sqlBuffer.append("from Payoff p where payoffState=0");
if(payoff.getPayoffRegistrar()!=null ){
sqlBuffer.append("and payoffRegistrar like '%"+payoff.getPayoffRegistrar()+"%'");
}
}
else if(payoff.getPayoffState()!=0){
if(payoff.getPayoffRegistrar()!=null ){
sqlBuffer.append("from Payoff p where payoffRegistrar like '%"+payoff.getPayoffRegistrar()+"%' and payoffState="+payoff.getPayoffState());
}
if(payoff.getPayoffCheckperson()!=null ){
sqlBuffer.append(" and payoffCheckperson like '%"+payoff.getPayoffCheckperson()+"%' and payoffState="+payoff.getPayoffState());
}
if(payoff.getPayoffRegisterTime()!=null && payoff.getPayoffCheckTime()!=null){
sqlBuffer.append(" and payoffRegisterTime>='"+payoff.getPayoffRegisterTime()+"' and payoffRegisterTime<='"+payoff.getPayoffCheckTime()+"'");
}
}
List payoffList=hibernateSession.createQuery(sqlBuffer.toString()).list(); return payoffList; }
若想用2个不嵌套的form,提交到1个action(多方法),也可用DispatchAction;
若想用2个不嵌套的form,提交到2个不同的action,则可仿照8楼的做法,或是用document.form[0](第一个form),document.form[1](第二个form);
若是2个嵌套的form,可用8楼的见解。
这样是最好的,如果感觉不好看,可以使用URL重写啊,O(∩_∩)O哈哈~
attribute="firstForm"
input="/chat/chat_room.jsp"
name="firstForm"
parameter="method"
path="/first"
scope="request"
type="com.qbar.struts.action.ChatroomAction">
<forward name="suc" path="/chat/chat_room.jsp" />
</action>
<action
attribute="sForm"
input="/chat/chat_room.jsp"
name="sForm"
parameter="method"
path="/s"
scope="request"
type="com.qbar.struts.action.ChatroomAction">
<forward name="suc" path="/chat/chat_room.jsp" />
</action>