我有一个如下的jsp。
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<form name="a" action="abc.jsp" method="post">
<input type="abc" id="abc" name="abc">
<input type="def" id="def" name="def"></form>
</body>
</html>
and the jsp that it is redirected is as below
<%@include file="DBCon.jsp" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<%try
{
int s;
String a=request.getParameter("a");
String b=request.getParameter("b");
String c=request.getParameter("Ship_ID");
ps=con.prepareStatement("select TSI_QUERY,TSI_R,TSI_C,SI_QUERY,SI_R, SI_C from topical");
rs=ps.executeQuery();
if(rs.next()){
if(rs.getString("TSI_Query")==null && rs.getString("SI_Query")!=null)
{
String p="update topical set SI_Query='"+a+"', SI_R='x',SI_C='y' where Job_ID='"+c+"'";
System.out.print(p);
/*ps1=con.prepareStatement("update topical set TSI_Query=?, TSI_R=?,TSI_C=?");
ps1.setString(1, a);
ps1.setString(2, "x");
ps1.setString(3, "y");
s=ps1.executeUpdate();
if(s!=0){
String redirectURL= "a.jsp";
response.sendRedirect(redirectURL);
}*/
}
else if(rs.getString("SI_Query")==null && rs.getString("TSI_Query")!=null)
{
String p="update topical set SI_Query='"+b+"', SI_R='x',SI_C='y'where Job_ID='"+c+"'";
System.out.print(p);
/*ps1=con.prepareStatement("update topical set SI_Query=?, SI_R=?,SI_C=?");
ps1.setString(1, b);
ps1.setString(2, "x");
ps1.setString(3, "y");
s=ps1.executeUpdate();
if(s!=0){
String redirectURL= "a.jsp";
response.sendRedirect(redirectURL);}*/
}
else if(rs.getString("SI_Query")==null && rs.getString("TSI_Query")==null){
if(a==null && b!=null)
{
String p="update topical set TSI_Query='"+a+"', TSI_R='x',TSI_C='y'where Job_ID='"+c+"'";
/* ps1=con.prepareStatement("update topical set TSI_Query=?, TSI_R=?,TSI_C=?");
ps1.setString(1, a);
ps1.setString(2, "x");
ps1.setString(3, "y");
s=ps1.executeUpdate();
if(s!=0){
String redirectURL= "a.jsp";
response.sendRedirect(redirectURL);
}
*/ }
else if(b==null && a!=null){
String p="update topical set SI_Query='"+b+"', SI_R='x',SI_C='y'where Job_ID='"+c+"'";
System.out.print(p);
/*
ps1=con.prepareStatement("update topical set SI_Query=?, SI_R=?,SI_C=?");
ps1.setString(1, b);
ps1.setString(2, "x");
ps1.setString(3, "y");
s=ps1.executeUpdate();
if(s!=0){
String redirectURL= "a.jsp";
response.sendRedirect(redirectURL);
}*/
}
}
}
}
catch(Exception e)
{
out.println(e);
}
%>
</body>
</html>
这里我想更新我的数据库表,收到非空值,另一列不应该更新为null,因为此列可能会在另一次更新。但是,它显示的是空白页面,而不是任何查询字符串,请让我知道如何显示该查询字符串。
由于
答案 0 :(得分:0)
如果我尝试理解您的代码,您似乎有三种情况
案例1
TSI_Query == null && SI_Query != null
//print something
案例2
SI_Query ==null && TSI_Query != null
//print something
案例3
SI_Query ==null && TSI_Query == null
// check values of a and b, and print only if b==null && a!=null
所以你有效, NOT 遵循所有可能的路径!难怪你没有任何输出。请注意,你也可能是其他问题。