jsp exception 问题

来源:百度知道 编辑:UC知道 时间:2024/06/05 12:18:35
<%@ page contentType = "text/html; charset = GB2312"%>
<%
String passed = "5";
passed = request.getParameter("birthDate");
StringBuffer content = new StringBuffer("");

response.setContentType("text/xml");
response.setHeader("Cache-Control","no-cache" );
content.append("<?xml version=\"1.0\" encoding= \"GB2312\"?>");
content.append("<contents>");
if(passed.equals("5"))
{
content.append("<city>青岛</city>");
content.append("<city>烟台</city>");
content.append("<city>济南</city>");
content.append("<city>莱芜</city>");
}
else
{
content.append("<city>郑州</city>");
content.append("<city>新乡</city>&q

passed = request.getParameter("birthDate");
上面的你确定不会得到一个null,
如果 passed 是一个 null, 11行的 if(passed.equals("5")) 就会出错

=======================================
if(passed.equals("5"))
改成:
if("5".equals(passed))
应该就好了试试