程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> java web-新手請問servlet不能在前端顯示全部字符串的問題

java web-新手請問servlet不能在前端顯示全部字符串的問題

編輯:編程綜合問答
新手請問servlet不能在前端顯示全部字符串的問題

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">


My JSP 'testServlet.jsp' starting page



'${testServlet }'

頁面結果

![圖片說明](http://img.ask.csdn.net/upload/201501/29/1422508578_590926.png)
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved