servlet如何跳转页面
一个很简单的servel程序,代码如下publicvoiddoPost(HttpServletRequestrequest,HttpServletResponseresp...
一个很简单的servel程序,代码如下
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String driver = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
String url = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=tonghai";
String username = "sa";
String password = "";
String codetemp=request.getParameter("username");
String passtemp=request.getParameter("password");
String strsql = "select password from bas_czjbm where bas_code=" + codetemp;
try {
Class.forName(driver);// 加载驱动
Connection conn=java.sql.DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=tonghai","sa","");
Statement stmt = conn.createStatement();
ResultSet rdoset=stmt.executeQuery(strsql);
while (rdoset.next()){
//if rdoset.getString("password")!=request.getParameter("password"){
//}else{
//}
}
rdoset.close();
stmt.close();
conn.close();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
}
中间注释一段,我想实现,如果数据库查询出的密码与表单上的密码一样则跳到下一页面,反之,弹出一提示框,提示密码不符,请问各位大侠,这段代码该如何实现?就这点财富了,多谢各位! 展开
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String driver = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
String url = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=tonghai";
String username = "sa";
String password = "";
String codetemp=request.getParameter("username");
String passtemp=request.getParameter("password");
String strsql = "select password from bas_czjbm where bas_code=" + codetemp;
try {
Class.forName(driver);// 加载驱动
Connection conn=java.sql.DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=tonghai","sa","");
Statement stmt = conn.createStatement();
ResultSet rdoset=stmt.executeQuery(strsql);
while (rdoset.next()){
//if rdoset.getString("password")!=request.getParameter("password"){
//}else{
//}
}
rdoset.close();
stmt.close();
conn.close();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
}
中间注释一段,我想实现,如果数据库查询出的密码与表单上的密码一样则跳到下一页面,反之,弹出一提示框,提示密码不符,请问各位大侠,这段代码该如何实现?就这点财富了,多谢各位! 展开
8个回答
展开全部
String password=request.getParameters("password");
if(password rdoset.getString("password")!){
response.sendRedirect("xxx.jsp");
}else{
printWriter out=response.getWriter();
out.print("<script>alert('密码不符')</script>");
}
if(password rdoset.getString("password")!){
response.sendRedirect("xxx.jsp");
}else{
printWriter out=response.getWriter();
out.print("<script>alert('密码不符')</script>");
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
servlet中这样写:
request.setAttribute("str", s);
request.getRequestDispatcher("这里写要跳转jsp页面的路径").forward(request, response);
在jsp中得到有两种方法,第一种:
<%=request.getAttribute("str");%>
或$
request.setAttribute("str", s);
request.getRequestDispatcher("这里写要跳转jsp页面的路径").forward(request, response);
在jsp中得到有两种方法,第一种:
<%=request.getAttribute("str");%>
或$
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
function showNews(n) {
var form = document.getElementById("news");
form.action = "showDetail!getMenuNames.action?DetailID=" + n;
form.submit();
}
<form id="news" method="post">
<input type="button" value="提交" onclick="showNews(n)">
</form>
带参数调整
或直接
<a href="showDetail!getMenuNames.action?参数名=参数值">
var form = document.getElementById("news");
form.action = "showDetail!getMenuNames.action?DetailID=" + n;
form.submit();
}
<form id="news" method="post">
<input type="button" value="提交" onclick="showNews(n)">
</form>
带参数调整
或直接
<a href="showDetail!getMenuNames.action?参数名=参数值">
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询