很诡异的问题。
请看注释部分
package com.nong;import javax.servlet.*;import javax.servlet.http.*;import java.io.*;import java.sql.*;public class Lgcl extends HttpServlet {public void doGet(HttpServletRequest req,HttpServletResponse res)throws ServletException,IOException{ res.setContentType("text/html;charset=gbk"); Sqlhelp sh=null; ResultSet Daset=null; PrintWriter pw=res.getWriter(); String u=req.getParameter("username"); String p=req.getParameter("passwd"); try{ String sqlstr="select * from users where users='"+u+"'and pwd='"+p+"'"; String sqlstr1="insert into users values('admin','123')"; sh=new Sqlhelp(); /* * 如果执行这段,下面就不会打印出结果,不执行的话会打印出结果 if(sh.doIt(sqlstr1)) { pw.println("插入成功"); } else { pw.println("插入失败"); } */ Daset=sh.getRs(sqlstr); while(Daset.next()) { for(int i=1;i<=2;i++) { pw.println(Daset.getObject(i)); } pw.println("<br>"); } } catch(Exception e) { e.printStackTrace(); } finally { sh.closeall(); sh.closeone(Daset); } }public void doPost(HttpServletRequest req,HttpServletResponse res)throws ServletException,IOException{ this.doGet(req,res);} }