一个页面中有多个form要怎样处理
展开全部
可以的,直接创建多个form即可,形式就是“<form></form><form></form>”,此时每个form中的内容就是独立提交的部分。
举例:
<form id='modify1' name="modify1" method="post" enctype="multipart/form-data" action="${ctx}/report/rate_exchange.jsp" >
<table class="table_common" id="table1" cellspacing="1" cellpadding="0">
<tr class='title_tr' >
<td style="white-space: nowrap; text-align: center;" colspan="4">
举例:
<form id='modify1' name="modify1" method="post" enctype="multipart/form-data" action="${ctx}/report/rate_exchange.jsp" >
<table class="table_common" id="table1" cellspacing="1" cellpadding="0">
<tr class='title_tr' >
<td style="white-space: nowrap; text-align: center;" colspan="4">
2017-05-27
展开全部
首先是提交页面:三个表单(form1,form2,form3)
<form name="form1" method="post" action="checklogin.jsp" class="niceform">
<input name="qx" type="hidden" value="3">
<label for="textinput">帐号:</label>
<input type="text" id="textinput" name="uid" size="12" />
<br />
<label for="passwordinput">密码:</label>
<input type="password" id="passwordinput" name="pwd" size="12" />
<br />
<input name="" type="submit" value="提交">
<input type="reset" name="Submit2" value="重置" />
</form>
</div>
<div class=tagContent id=tagContent1>欢迎使用本系统,请先【登陆】或【注册】。
<form name="form2" method="post" action="checklogin.jsp" class="niceform">
<input name="qx" type="hidden" value="2">
<label for="textinput">帐号:</label>
<input type="text" id="textinput" name="uid" size="12" />
<br />
<label for="passwordinput">密码:</label>
<input type="password" id="passwordinput" name="pwd" size="12" />
<br />
<input name="Submit1" type="submit" id="Submit1" value="提交" />
<input type="reset" name="Submit2" value="重置" />
</form>
</div>
<div class=tagContent id=tagContent2>欢迎使用本系统,请先【登陆】然后进行管理。
<form name="form3" method="post" action="admin/checklogin.jsp" class="niceform">
<input name="qx" type="hidden" value="1">
<label for="textinput">帐号:</label>
<input type="text" id="textinput" name="uid" size="12" />
<br />
<label for="passwordinput">密码:</label>
<input type="password" id="passwordinput" name="pwd" size="12" />
<br />
<label for="passwordinput">验证:</label>
<input type="text" id="passwordinput" name="ad" size="4" />
<br />
<input name="Submit1" type="submit" id="Submit1" value="提交" />
<input type="reset" name="Submit2" value="重置" />
</form>
处理页面:
<%@ page contentType="text/html; charset=gb2312" language="Java" import="java.sql.*" errorPage="" %>
<%@ include file="conn.jsp" %>
<%
request.setCharacterEncoding("gb2312");
String sqx=request.getParameter("qx");
int qx =Integer.parseInt(sqx);
String uid=request.getParameter("uid");
String pwd= request.getParameter("pwd");
String sql=null;
switch(qx){
case 1:sql="select * from admin where admin='"+uid+"' and pwd='"+pwd+"'";break;
case 2:sql="select * from department where d_admin='"+uid+"' and d_pwd='"+pwd+"'";break;
case 3:sql="select * from student where s_name='"+uid+"' and s_pwd='"+pwd+"'";break;
}
rs=stmt.executeQuery(sql);
boolean flag=false;
if(rs.next()){flag=true;}
if(flag==true)
{
session.setAttribute("uid",uid);
session.setAttribute("pwd",pwd);
session.setAttribute("type",sqx);
session.setAttribute("sflag","qgzx");
switch(qx){
case 1:response.sendRedirect("admin.jsp");break;
case 2:response.sendRedirect("d_manage.jsp");break;
case 3:response.sendRedirect("s_manage.jsp");break;
}
}
else{
session.setAttribute("uid",null);
session.setAttribute("pwd",null);
session.setAttribute("type",null);
%><jsp:forward page="error.jsp"/><%
}
}
catch(SQLException e2){out.println(e2);}
//rs.close();
//conn.close();
%>
<form name="form1" method="post" action="checklogin.jsp" class="niceform">
<input name="qx" type="hidden" value="3">
<label for="textinput">帐号:</label>
<input type="text" id="textinput" name="uid" size="12" />
<br />
<label for="passwordinput">密码:</label>
<input type="password" id="passwordinput" name="pwd" size="12" />
<br />
<input name="" type="submit" value="提交">
<input type="reset" name="Submit2" value="重置" />
</form>
</div>
<div class=tagContent id=tagContent1>欢迎使用本系统,请先【登陆】或【注册】。
<form name="form2" method="post" action="checklogin.jsp" class="niceform">
<input name="qx" type="hidden" value="2">
<label for="textinput">帐号:</label>
<input type="text" id="textinput" name="uid" size="12" />
<br />
<label for="passwordinput">密码:</label>
<input type="password" id="passwordinput" name="pwd" size="12" />
<br />
<input name="Submit1" type="submit" id="Submit1" value="提交" />
<input type="reset" name="Submit2" value="重置" />
</form>
</div>
<div class=tagContent id=tagContent2>欢迎使用本系统,请先【登陆】然后进行管理。
<form name="form3" method="post" action="admin/checklogin.jsp" class="niceform">
<input name="qx" type="hidden" value="1">
<label for="textinput">帐号:</label>
<input type="text" id="textinput" name="uid" size="12" />
<br />
<label for="passwordinput">密码:</label>
<input type="password" id="passwordinput" name="pwd" size="12" />
<br />
<label for="passwordinput">验证:</label>
<input type="text" id="passwordinput" name="ad" size="4" />
<br />
<input name="Submit1" type="submit" id="Submit1" value="提交" />
<input type="reset" name="Submit2" value="重置" />
</form>
处理页面:
<%@ page contentType="text/html; charset=gb2312" language="Java" import="java.sql.*" errorPage="" %>
<%@ include file="conn.jsp" %>
<%
request.setCharacterEncoding("gb2312");
String sqx=request.getParameter("qx");
int qx =Integer.parseInt(sqx);
String uid=request.getParameter("uid");
String pwd= request.getParameter("pwd");
String sql=null;
switch(qx){
case 1:sql="select * from admin where admin='"+uid+"' and pwd='"+pwd+"'";break;
case 2:sql="select * from department where d_admin='"+uid+"' and d_pwd='"+pwd+"'";break;
case 3:sql="select * from student where s_name='"+uid+"' and s_pwd='"+pwd+"'";break;
}
rs=stmt.executeQuery(sql);
boolean flag=false;
if(rs.next()){flag=true;}
if(flag==true)
{
session.setAttribute("uid",uid);
session.setAttribute("pwd",pwd);
session.setAttribute("type",sqx);
session.setAttribute("sflag","qgzx");
switch(qx){
case 1:response.sendRedirect("admin.jsp");break;
case 2:response.sendRedirect("d_manage.jsp");break;
case 3:response.sendRedirect("s_manage.jsp");break;
}
}
else{
session.setAttribute("uid",null);
session.setAttribute("pwd",null);
session.setAttribute("type",null);
%><jsp:forward page="error.jsp"/><%
}
}
catch(SQLException e2){out.println(e2);}
//rs.close();
//conn.close();
%>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询