servlet查詢代碼如下
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
ServletOutputStream out=response.getOutputStream();
String stnm=request.getParameter("stnm");
try {
Statement stat = conn.createStatement();
ResultSet rs = stat.executeQuery("select * from qstation where stnm ='"+stnm+"'");
while (rs.next()) {
ResultSetMetaData rsmd1 = rs.getMetaData();
int count = rsmd1.getColumnCount();
String all="";
for (int i =1; i < count+1; i++) {
all=all+rs.getString(i)+",";
}
System.out.println(all);
out.println(all);
}
} catch (Exception e) {
// TODO: handle exception
}
}
system.out.println打印的消息是:
58238,320101,null,060602,南京,11880.0,3200.0,1,125.0,null,蘇,南京市,南京市轄區,長江流域,中下游區,長江下游,101190101,華東電網,江蘇,1,01,01,2,2,1,220101,
但是前台頁面只顯示:58238,320101,null,060602,
請問這是什麼問題?
package com.rss.web;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class TestServlet extends HttpServlet{
/**
*
*/
private static final long serialVersionUID = 1L;
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
doPost(req, resp);
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
resp.setContentType("text/html");
String all="58238,320101,null,060602,南京,11880.0,3200.0,1,125.0,null,蘇,南京市,南京市轄區,長江流域,中下游區,長江下游,101190101,華東電網,江蘇,1,01,01,2,2,1,220101,";
System.out.println(all);
req.setAttribute("testServlet", all);
req.getRequestDispatcher("/testServlet.jsp").forward(req, resp);
}
}
web.xml
testServlet
com.rss.web.TestServlet
testServlet
/test.do
test.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
頁面結果
![圖片說明](http://img.ask.csdn.net/upload/201501/29/1422508578_590926.png)