2 u012168481 u012168481 于 2013.09.18 12:03 提问

servlet里的问题,本人初学者,请各位指教

public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("GB18030");
response.setContentType("text/html;charset=GB18030");

PrintWriter out = response.getWriter();
out
.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
Person per=new Person();

 String act=request.getParameter("act");

String name=request.getParameter("pname");
String type=request.getParameter("ptype");
String price=request.getParameter("pprice");
String enterd=request.getParameter("penterdate");
per.setPname(name);
per.setPtype(type);
per.setPprice(price);
per.setPenterdate(enterd);

if("insert".equals(act)){

if(insert(per)==true){
out.println("添加成功!");
request.setCharacterEncoding("GB18030");
response.setContentType("text/html;charset=GB18030");
out.println("");
out.println("

A Servlet");
out.println(" ");
out.print("跳转 ");
out.print(this.getClass());
out.println(", using the POST method");
out.println(" ");
out.println("");
out.flush();
out.close();
}else{
out.println("添 加失败!");
}
}else if("query".equals(act)){
query(name,type);//不走这里的,是怎么回事啊?
out.println("true123");
}else{
out.println("查询失败!");
}

}

public void query(String name,String type){//查询模块

Connection con = xc.OraLJ();//连接数据库的方法

 Statement st=null;
 ResultSet rs=null;
 String sql="select * from product";
 try {
  System.out.println("trueavbbbbb");

st=con.createStatement();
rs=st.executeQuery(sql);
while(rs.next()){
System.out.println();
System.out.println("************************");
System.out.println("id:" + rs.getString("pid"));
System.out.println("name:" + rs.getString("pname"));
System.out.println("type:" + rs.getString("ptype"));
System.out.println("price:" + rs.getString("pprcie"));
System.out.println("enterdate:" + rs.getString("penterdate"));
System.out.println();
System.out.println("************************");
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{

xc.Close(st);
xc.Close(con);
}

}

1个回答

en_joker
en_joker   2017.11.16 13:09

建议你打一个断点,用debug模式启动,然后查看判断哪里是否有问题。

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!