在學習java ee的時候。用事例的代碼跑項目的時候出現(xiàn)顯示不全的問題,重啟電腦和服務器都無果。找了很久的毛病都沒有找到,特來請教大家,還望大家能夠解答,謝謝!
下面上代碼:
if(isUserExist){
req.setAttribute("login", loginValue);
try {
getOrderList(req, resp);
} catch (SQLException e) {
e.printStackTrace();
}
displayMyStocklistPage(req, resp);
}else{
displayErrorPage(req,resp);
}
在這個servlet中調(diào)用了(displayMystocklistPage )這兩個方法來畫界面。
下面是方法內(nèi)容:
public void displayMyStocklistPage(HttpServletRequest req, HttpServletResponse res) throws IOException {
ArrayList list = (ArrayList) req.getAttribute("list"); // resp.sendRedirect(req.getContextPath()+"/MyStockList");
boolean isItemOut = false;
PrintWriter out = res.getWriter();
//用本地的out查看內(nèi)容
//PrintStream out = null ; // 聲明打印流對象
// 如果現(xiàn)在是使用FileOuputStream實例化,意味著所有的輸出是向文件之中
// out = new PrintStream(new FileOutputStream(new File("/Users/insomnialee/Downloads/Sample-20171227/sample2/web/test.txt"))) ;
out.println("<html><head>");
out.println("<script src=\"https://ajax.googleapis.com/ajax/libs/angularjs/1.6.6/angular.min.js\"></script>\n" +
" <style>\n" +
" table, th , td {\n" +
" border: 1px solid grey;\n" +
" border-collapse: collapse;\n" +
" padding: 5px;\n" +
" }\n" +
" table tr:nth-child(odd) {\n" +
" background-color: #f1f1f1;\n" +
" }\n" +
" table tr:nth-child(even) {\n" +
" background-color: #ffffff;\n" +
" }\n" +
" </style>\n" +
"</head>\n" +
"<body>");
out.println("<table width='650' border='0' >");
out.println("<tr>");
out.println("<td width='650' height='80' background='" + req.getContextPath() + "/image/top.jpg'> </td>");
out.println("</tr>");
out.println("</table>");
out.println("<p>Welcome " + req.getAttribute("login") + "</p>");
out.println("My Order List: ");
out.println("<br>");
out.println("<table>");
out.println("<tr>"+
"<td>"+"日期"+"</td>"+
"<td>"+"id"+"</td>"+
"<td>"+"商品名稱"+"</td>"+
"<td>"+"數(shù)量"+"</td>"+
"<td>"+"總價"+"</td>"+
"<td>"+"商品狀態(tài)"+"</td>"+
"</tr>");
for (int i = 0; i < list.size(); i++) {
Order order = (Order) list.get(i);
out.println("<tr>"+
"<td>"+order.getDate().toString()+"</td>"+
"<td>"+order.getUid()+"</td>"+
"<td>"+order.getCname()+"</td>"+
"<td>"+order.getCnum()+"</td>"+
"<td>"+order.getPrice()+"</td>"
);
if(order.getIsout()==0){
isItemOut = true;
out.println("<td>"+"-缺貨中-"+"</td>");
}else{
out.println("<td>"+"-正常-"+"</td>");
}
out.println("</tr>");
}
out.println("</table>");
// out.println("</p>");
if(isItemOut){
out.println("<p style=\"color:red\"> 您訂單中有部分商品缺貨! </p>");
}
out.println("Click <a href='" + res.encodeURL(req.getRequestURI()) + "'>here</a> to reload this page.<br>");
out.println("<form method='GET' action='" + res.encodeURL(req.getContextPath() + "/Login") + "'>");
out.println("<input value='Logout'>");
out.println("</form>");
out.println("<p>Servlet is version @version@</p>");
out.println("</body></html>");
//displayout page
//out.close();
}
最后展示出來的界面是這樣的
//插圖老是失敗,用文字描述下吧,最后的界面中沒有代碼最后<input>和<p>這兩個標簽??蛻舳私邮盏降膆tml中只有一個空的<form>,而在我測試的時候發(fā)現(xiàn),刪去后面的一些展示代碼。前面本來能夠正常顯示的甚至還會變得不正常顯示。我也做了將輸出輸出到txt然后在當成html文件打開的辦法,這樣測試出來的界面是正常的。所以懷疑是通信有大小限制,在out中查看的時候,又看到?jīng)]有達到limit的限制值(8192),,希望過來人能夠指點迷津,,謝謝?。?/p>
flush public abstract void flush() throws IOExceptionFlush
Flush the stream. If the stream has saved any characters from the various write() methods in a buffer, write them immediately to their intended destination. Then, if that destination is another character or byte stream, flush it. Thus one flush() invocation will flush all the buffers in a chain of Writers and OutputStreams.
The method may be invoked indirectly if the buffer size is exceeded.
Once a stream has been closed, further write() or flush() invocations will cause an IOException to be thrown.
可能是字符串超出緩存區(qū)了,自己算算,在合適的地方調(diào)用out.flush()吧.
北大青鳥APTECH成立于1999年。依托北京大學優(yōu)質(zhì)雄厚的教育資源和背景,秉承“教育改變生活”的發(fā)展理念,致力于培養(yǎng)中國IT技能型緊缺人才,是大數(shù)據(jù)專業(yè)的國家
北大青鳥中博軟件學院創(chuàng)立于2003年,作為華東區(qū)著名互聯(lián)網(wǎng)學院和江蘇省首批服務外包人才培訓基地,中博成功培育了近30000名軟件工程師走向高薪崗位,合作企業(yè)超4
中公教育集團創(chuàng)建于1999年,經(jīng)過二十年潛心發(fā)展,已由一家北大畢業(yè)生自主創(chuàng)業(yè)的信息技術與教育服務機構,發(fā)展為教育服務業(yè)的綜合性企業(yè)集團,成為集合面授教學培訓、網(wǎng)
達內(nèi)教育集團成立于2002年,是一家由留學海歸創(chuàng)辦的高端職業(yè)教育培訓機構,是中國一站式人才培養(yǎng)平臺、一站式人才輸送平臺。2014年4月3日在美國成功上市,融資1
曾工作于聯(lián)想擔任系統(tǒng)開發(fā)工程師,曾在博彥科技股份有限公司擔任項目經(jīng)理從事移動互聯(lián)網(wǎng)管理及研發(fā)工作,曾創(chuàng)辦藍懿科技有限責任公司從事總經(jīng)理職務負責iOS教學及管理工作。
浪潮集團項目經(jīng)理。精通Java與.NET 技術, 熟練的跨平臺面向?qū)ο箝_發(fā)經(jīng)驗,技術功底深厚。 授課風格 授課風格清新自然、條理清晰、主次分明、重點難點突出、引人入勝。
精通HTML5和CSS3;Javascript及主流js庫,具有快速界面開發(fā)的能力,對瀏覽器兼容性、前端性能優(yōu)化等有深入理解。精通網(wǎng)頁制作和網(wǎng)頁游戲開發(fā)。
具有10 年的Java 企業(yè)應用開發(fā)經(jīng)驗。曾經(jīng)歷任德國Software AG 技術顧問,美國Dachieve 系統(tǒng)架構師,美國AngelEngineers Inc. 系統(tǒng)架構師。