失恋之后,特别想回答问题!祝福所有的人好运!我不懂jsp,连一眼都没看过. 至少有一种方法可以解决,
<%
response.write "<script>
response.write "var str='"&request("name")&"';"
response.write "alert(str);"
response.write "</script>"
%>
这是asp语法,我不知道jsp是什么样,意思是一样的,这样可以把服务器端的参数传给客户端,虽然有点土,很实用。注意别忘了分号;
<%
response.write "<script>
response.write "var str='"&request("name")&"';"
response.write "alert(str);"
response.write "</script>"
%>
这是asp语法,我不知道jsp是什么样,意思是一样的,这样可以把服务器端的参数传给客户端,虽然有点土,很实用。注意别忘了分号;
用method=post方式提交表单,参数不会显示在地址栏
window.location="delGcs.jsp?str="+dept_id+"&flag=<%=flag%>";
</script>
var name=<%=name%>;
这样就可以了。
<script>
stringValue=<%=jspValue%>
</script>
function linktopage()
{
IDCARD=document.form1.test1.value;
pageCount=document.from1.pageCount.value;
sqlcount=document.form1.sqlcount.value;
currPage=document.form1.currPage.value;
document.form1.submit();
}
</script>
<script lanugage="javascript">
function form2()
{
IDCARD=document.form2.test1.value;
pageCount=document.form2.pageCount.value;
sqlcount=document.form2.sqlcount.value;
currPage=document.form2.currPage.value;
currPage=currPage-1+2;
}
</script>
<%if(currPage>1){%>
<a href="javascript:form1()">上一页</a>
<%}%>
<%if(currPage<pageCount){%>
<a href="javascript:form2()">
下一页</a>
<%}%>
为什么点下一页好用?上一页错误:不支持此方法呢?还有,为什么必须用 window.location="mytest.jsp?IDCARD="+IDCARD+"&page="+page+"&sqlcount="+sqlcount+"";可用?而document.form.submit();却查不到信息呢?
其实我用form的目的就是隐藏参数,如果用window.location的话就失去意义了!急!!!!
form提交应该可以取到的呀
<%@ page import="java.util.Date"%>
<%@ page language="java"%>
<script lanugage="javascript">
function form1()
{
IDCARD=document.form1.test1.value;
pageCount=document.from1.pageCount.value;
sqlcount=document.form1.sqlcount.value;
currPage=document.form1.currPage.value;
document.form1.submit();
// window.location="mytest.jsp?IDCARD="+IDCARD+"&page="+page+"&sqlcount="+sqlcount+"";
//window.event.returnValue=false;
}
</script>
<script lanugage="javascript">
function form2()
{
IDCARD=document.form2.test1.value;
pageCount=document.form2.pageCount.value;
sqlcount=document.form2.sqlcount.value;
currPage=document.form2.currPage.value;
currPage=currPage-1+2;
// document.write(currPage);
//document.form2.submit();
window.location="mytest.jsp?IDCARD="+IDCARD+"&page="+currPage+"&sqlcount="+sqlcount+"";
//window.event.returnValue=false;
}
</script><%
Class.forName("oracle.jdbc.driver.OracleDriver"); //设置数据库连接字符串 String sConn = "jdbc:oracle:thin:@clgl:1521:carweb"; //连接数据库 Connection conn = java.sql.DriverManager.getConnection(sConn,"carmanager","car"); //创建SQL语句对象 Statement sqlStmt = conn.createStatement();
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE); Statement stmtcount=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE); String Rsdriver__MMColParam = "-1";
if (request.getParameter("IDCARD") !=null) {Rsdriver__MMColParam = (String)request.getParameter("IDCARD");}
ResultSet rs=stmt.executeQuery("select * from driver where idcard like '"+Rsdriver__MMColParam+"%' ");
boolean rs_isEmpty = !rs.next();
boolean rs_hasData = !rs_isEmpty;
%>
<%
int currPage;
String sqlcount;
ResultSet rscount=null;
if(request.getParameter("page")==null)
{ sqlcount="select count(*) from driver where idcard like '"+Rsdriver__MMColParam+"%'";
rscount=stmtcount.executeQuery(sqlcount);
}else {
sqlcount=request.getParameter("sqlcount"); }int pageSize=10;int rowCount=0; //总的记录数
if(request.getParameter("page")==null)
{
while (rscount.next()){
rowCount=rscount.getInt(1);
sqlcount=(new Integer(rowCount)).toString();
}
}
else {
rowCount=Integer.parseInt(sqlcount);
// out.println("rowcount "+rowCount);
}int pageCount; //总的页数
String strPage;
strPage=request.getParameter("page");
if (strPage==null){
currPage=1;
}
else{ currPage=Integer.parseInt(strPage); if (currPage<1) currPage=1; } pageCount=(rowCount+pageSize-1)/pageSize; if (currPage>pageCount) currPage=pageCount;
int thepage=(currPage-1)*pageSize;
%><html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"></head><body bgcolor="#FFFFFF" text="#000000">
<form name="form1" method="post" action="mytest.jsp">
<input type="hidden" name="test1" value="<%=request.getParameter("IDCARD")%>">
<input type="text" name="IDCARD">
<input type="submit" name="Submit" value="Submit">
<input type="hidden" name="pageCount" value="<%=request.getParameter("pageCount")%>">
<input type="hidden" name="sqlcount" value="<%=sqlcount%>">
<input type="hidden" name="currPage" value="<%=request.getParameter("currPage")+1%>">
</form>
<p><br>
<form name="form2" method="post" action="">
<input type="hidden" name="test1" value="<%=request.getParameter("IDCARD")%>">
<input type="hidden" name="pageCount" value="<%=pageCount%>">
<input type="hidden" name="sqlcount" value="<%=sqlcount%>">
<input type="hidden" name="currPage" value="<%=currPage%>">
</form>
<p><br>
</p> <%
if (!rs_isEmpty ) { int n=0;
rs.absolute(thepage+1); while (n<(pageSize)&&!rs.isAfterLast()){
%>
<table width="75%" border="1" align="center">
<tr>
<td><%=rs.getString("drivername")%></td>
<td><%=rs.getString("idcard")%></td>
<td><%=rs.getString("drivercard")%></td>
</tr>
</table>
<div align="center">
<% rs.next(); n++; }
}
%>
<%if(currPage>1){%>
<a href="insertdriver.jsp?IDCARD=<%=Rsdriver__MMColParam%>">
首页</a>
<%}%>
<%if(currPage>1){%>
<a href="javascript:form1()">上一页</a>
<%}%>
<%if(currPage<pageCount){%>
<a href="javascript:form2()">
下一页</a>
<%}%>
<%if(currPage<pageCount){%>
尾页
<%}%>
</div>
</body>
</html>
<%
if (rs!=null)
rs.close();
if (rscount!=null)
rscount.close();
if (stmt!=null)
stmt.close();
if (stmtcount!=null)
stmtcount.close();
if (conn!=null)
conn.close();
%>
<script lanugage="javascript">
function linktopage()
{
IDCARD=document.form1.test1.value;
pageCount=document.from1.pageCount.value;
sqlcount=document.form1.sqlcount.value;
currPage=document.form1.currPage.value;
document.form1.submit();
}
</script><a href="java script:form1()">上一页</a>
<a href="java script:form2()">
下一页</a>
为什么点下一页时页面为空了呢?除非用window.location="...?.."
呢?但我不能用这种方法。
2.form提交是可以取到参数的,将代码节选了一些,看看就可明白
为调试方便,将hidden暂显示为text刚才被类型转换的问题纠缠了一会儿,哎,java还是不熟啊
mytest.jsp
<%@ page contentType="text/html; charset=gb2312"%>
<script lanugage="javascript">
function form1()
{
//IDCARD=document.form1.test1.value;
/////////////////////////////
pageCount=document.form1.pageCount.value;
//////////////////////////////
//sqlcount=document.form1.sqlcount.value;
//currPage=document.form1.currPage.value;
document.form1.submit();
}
function form2()
{
//IDCARD=document.form2.test1.value;
//pageCount=document.form2.pageCount.value;
//sqlcount=document.form2.sqlcount.value;
currPage=document.form2.currPage.value;
currPage=currPage-1+2;
document.form2.submit();
}
</script><%
int sqlcount=5;
int pageCount=4;
int currPage=2;
int Rsdriver__MMColParam=3;
String currPagestr="";
%><html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"></head><body bgcolor="#FFFFFF" text="#000000">
<form name="form1" method="post" action="">
<%
currPagestr=request.getParameter("currPage");
if(currPagestr!=null)
currPage=Integer.parseInt(currPagestr)-1;
else
currPage=0;
%>
IDCARD<input type="text" name="IDCARD" value="<%=request.getParameter("IDCARD")%>">
<input type="submit" name="Submit" value="Submit">
pageCount<input type="text" name="pageCount" value="<%=request.getParameter("pageCount")%>">
sqlcount<input type="text" name="sqlcount" value="<%=sqlcount%>">
currPage<input type="text" name="currPage" value="<%=currPage%>">
</form>
<p><br>
<form name="form2" method="post" action="">
<%
currPagestr=request.getParameter("currPage");
if(currPagestr!=null)
currPage=Integer.parseInt(currPagestr)+1;
else
currPage=0;
%>
IDCARD<input type="text" name="IDCARD" value="<%=request.getParameter("IDCARD")%>">
<input type="submit" name="Submit" value="Submit">
pageCount<input type="text" name="pageCount" value="<%=request.getParameter("pageCount")%>">
sqlcount<input type="text" name="sqlcount" value="<%=sqlcount%>">
currPage<input type="text" name="currPage" value="<%=currPage%>">
</form>
<p><br>
</p><div align="center">
<%if(currPage>1){%>
<a href="insertdriver.jsp?IDCARD=<%=Rsdriver__MMColParam%>">
首页</a>
<%}%>
<%if(currPage>1){%>
<a href="javascript:form1()">上一页</a>
<%}%>
<%if(currPage<pageCount){%>
<a href="javascript:form2()">
下一页</a>
<%}%>
<%if(currPage<pageCount){%>
尾页
<%}%>
</div>
</body>
</html>