jsp equals() 问题

来源:百度知道 编辑:UC知道 时间:2024/05/22 02:38:11
<%@ page contentType="text/html; charset=gb2312" %>
<%@ page import="java.sql.*"%>
<jsp:useBean id="condata" scope="page" class="wuliu.conndata"/>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link rel="stylesheet" href="../CSS/style.css">
<title>
search page
</title>
</head>

<%!
ResultSet rs=null;
String sql="",rsql;
String text,style;
int n;
int pagesize=10;
int rowcount=0;
int pagecount=1;
String column[];
%>
<%
request.setCharacterEncoding("gb2312");
text=request.getParameter("text");
style=request.getParameter("style");
%>
<jsp:include page="/top.jsp"/>
<body bgcolor="#ffffff"&g

if(style.equals("db_CarMessage")) --》这里错误,为什么?

一般会报空值异常,当style为null时就会出现
可能是你style在前面没有取到值
style=request.getParameter("style");
没有取到值

改为:
if("db_CarMessage".equals(style))
可以避免style的null异常

记住常量和变量用equals比较时,常量放前面

你给style一个初始化值试试
String text,style; 把这句改成
String text=null;
String style=null;