jsp页面 显示bootstrap table内容无法显示

Everyday前进一步 2017-07-19 12:56:29
小弟第一次发帖。目前想做一个从bootstrap table利用jsp获取后台数据的这么一个数据库可视化程序。现在jsp程序在Eclipse控制台内是可以正常取值的,但在页面上却始终为空。麻烦各位大侠帮助我,实在是费解。
前端jsp代码如下:
			<form>

<div class="form-actions">
<button type="submit" class="btn btn-primary">确定</button>
</div>

<div class="widget widget-table">

<div class="widget-header">
<i class="icon-th-list"></i>
<h3>分销商信息</h3>
</div> <!-- /widget-header -->

<div class="widget-content">

<table class="table table-striped table-bordered" id="cusTable">
<thead>
<tr>
<th>分销商代码</th>
<th>分销商区域</th>
<th>分销商名称(SAP)</th>
<th>SAP代码</th>
<th>区域代码</th>
<th>所属物流中心</th>
<th>物流中心代码</th>
<th>省份</th>
<th>城市</th>
<th>分销商类别</th>
<th>备注</th>

</tr>
</thead>



<tbody>

<% Distributor_dao dao =new Distributor_dao();
List<distributor> list=dao.findAllDistributors();
for (distributor distri:list)
{ %>
<tr>

<td><% distri.getIdDistributor();%></td>
<td><% System.out.println(distri.getName()); %></td>
<td>Chicago Bulls</td>
<td>Beijing</td>
<td>Beijing</td>
<td>Beijing</td>
<td>Beijing</td>
<td>Beijing</td>
<td>Beijing</td>
</tr>
<% } %>
</tbody>


</table>

</div> <!-- /widget-content -->

</div> <!-- /widget -->
</form>

后台dao层代码:
public List< distributor > findAllDistributors() throws SQLException{
connectionBDD();
List <distributor> listDistributor=new ArrayList<distributor>();
rs = stmt.executeQuery("SELECT * FROM `basic info_distributors`;");
System.out.println("OK!");

while (rs.next()) {
distributor distriObjetTem=new distributor();
distriObjetTem.setCenter(rs.getString("所属物流中心"));
distriObjetTem.setCenterCity(rs.getString("所属物流中心2"));
distriObjetTem.setCity(rs.getString("所属城市"));
distriObjetTem.setCodeCenter(rs.getString("物流中心代码"));
distriObjetTem.setCodeRegion(rs.getInt("区域代码"));
distriObjetTem.setIdDistributor(rs.getString("分销商代码"));
distriObjetTem.setName(rs.getString("分销商名称(SAP)"));
distriObjetTem.setProvince(rs.getString("所属省份"));
distriObjetTem.setRegion(rs.getString("分销商区域"));
distriObjetTem.setRemark(rs.getString("备注"));
distriObjetTem.setSAP(rs.getInt("分销商SAP代码"));
distriObjetTem.setTypeDistributor(rs.getString("分销商类别"));
distriObjetTem.setValidation(rs.getString("是否有效"));
System.out.println(rs.getString("分销商代码"));
listDistributor.add(distriObjetTem);

}
System.out.println("Yeah!I've got a list of distributor from DB");
return listDistributor;

}

Eclipse本地测试结果:937条返回值
运行在服务器上后前端显示:
图片中的表格前两列是我用jsp想要获取的字段,后面几列都是静态的。问题就在这里,不知为何前面的信息无法显示在网页上。
一定是小弟的知识上欠缺了重要的一块,请各位一定帮个忙!谢谢啦
...全文
446 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
引用 7 楼 happybebe 的回复:
不建议在jsp上写java代码,你为什么不在请求页面的时候,把list直接返回到页面,然后用el表达式多简单
@Controller
@RequestMapping("/test")
public class myController {

@RequestMapping(value = "/mypage", method = RequestMethod.GET)
	public ModelAndView allload(HttpServletRequest request,
			HttpServletResponse response,
			ModelMap modelMap) throws Exception {
		ModelAndView mav = new ModelAndView();
		mav.setViewName("/test/mypage" );
		if (name.equals("user_list") ) {
			List<Object> userlist = yourService
					.findAllDistributors();
			mav.addObject("userlist", userlist);
		}
		return mav;
	}
}
比如以上代码,在你访问/test/mypage 的时候返回userlist 并跳转到mypage.jsp 然后在mypage.jsp页面用el表达式,写出来即可
<table class="table table-striped">
						<thead>
							<tr>
								<th style="width:70%">标题</th>
								<th style="width:15%;text-align:center">发布人</th>
								<th style="align:right;text-align:center;">发布日期</th>
							</tr>
						</thead>
						<tbody>
							<c:forEach items="${userlist}" var="News">
								<tr id="<c:out value="${News.id}"/>">
									<td style="width:70%"><a href="<%=request.getContextPath()%>/news/news_info/${News.id}" target="" style="">${News.title}</a></td>
									<td style="width:15%;text-align:center">${News.uname}</td>
									<td style="align:right;text-align:center"><fmt:parseDate value="${News.fbdate}"
											pattern="yyyy-MM-dd HH:mm:ss" var="myDate" /> <fmt:formatDate
											value="${myDate}" pattern="yyyy-MM-dd" /></td>
								</tr>
							</c:forEach>

						</tbody>
					</table>
您好,谢谢您的建议,这个项目中我没有用框架来写,确实造成了一定的困扰。后面的数据增改操作我想用servlet实现,您觉得这样如何?
  • 打赏
  • 举报
回复
不建议在jsp上写java代码,你为什么不在请求页面的时候,把list直接返回到页面,然后用el表达式多简单
@Controller
@RequestMapping("/test")
public class myController {

@RequestMapping(value = "/mypage", method = RequestMethod.GET)
	public ModelAndView allload(HttpServletRequest request,
			HttpServletResponse response,
			ModelMap modelMap) throws Exception {
		ModelAndView mav = new ModelAndView();
		mav.setViewName("/test/mypage" );
		if (name.equals("user_list") ) {
			List<Object> userlist = yourService
					.findAllDistributors();
			mav.addObject("userlist", userlist);
		}
		return mav;
	}
}
比如以上代码,在你访问/test/mypage 的时候返回userlist 并跳转到mypage.jsp 然后在mypage.jsp页面用el表达式,写出来即可
<table class="table table-striped">
						<thead>
							<tr>
								<th style="width:70%">标题</th>
								<th style="width:15%;text-align:center">发布人</th>
								<th style="align:right;text-align:center;">发布日期</th>
							</tr>
						</thead>
						<tbody>
							<c:forEach items="${userlist}" var="News">
								<tr id="<c:out value="${News.id}"/>">
									<td style="width:70%"><a href="<%=request.getContextPath()%>/news/news_info/${News.id}" target="" style="">${News.title}</a></td>
									<td style="width:15%;text-align:center">${News.uname}</td>
									<td style="align:right;text-align:center"><fmt:parseDate value="${News.fbdate}"
											pattern="yyyy-MM-dd HH:mm:ss" var="myDate" /> <fmt:formatDate
											value="${myDate}" pattern="yyyy-MM-dd" /></td>
								</tr>
							</c:forEach>

						</tbody>
					</table>
  • 打赏
  • 举报
回复
引用 2 楼 zc881124 的回复:
<% distri.getIdDistributor();%> 改成<%= distri.getIdDistributor();%>
感谢您的回复,问题已经得到解决,正是如您所说
  • 打赏
  • 举报
回复
引用 4 楼 tiaoxixiaoji 的回复:
2l说的对,通过java代码输出代码到页面有两种方式,一种是<%="aaaa"%>,另一种是<% out.print("sss")%>,至于<%System.out.println("xxx")%>则是输出到日志了
涨知识了,谢谢您的回复,后来自己试了一下,果然是2L所说的那个问题
tiaoxixiaoji 2017-07-19
  • 打赏
  • 举报
回复
2l说的对,通过java代码输出代码到页面有两种方式,一种是<%="aaaa"%>,另一种是<% out.print("sss")%>,至于<%System.out.println("xxx")%>则是输出到日志了
ghking1 2017-07-19
  • 打赏
  • 举报
回复
110成成 2017-07-19
  • 打赏
  • 举报
回复
<% distri.getIdDistributor();%> 改成<%= distri.getIdDistributor();%>
  • 打赏
  • 举报
回复
在控制台分别抽取前两列的字段也都是正常的,起码说明dao返回的list是没有问题的。另外在jsp中打印的内容也能在控制台内正常显示。不知原因到底为何

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧