java从数据库中读取的数据怎样显示在jsp的网页当中

 我来答
好程序员
2016-09-17 · HTML5前端培训/大数据培训/Java
好程序员
好程序员是IT高端课程培训基地,从平凡到卓越,为梦想而拼搏。
向TA提问
展开全部
我用的SSM框架 这是java类

@Controller
@RequestMapping("/studentController")
public class StudentController {

@Autowired
private StudentServices studentServices;

public StudentServices getStudentServices() {
return studentServices;
}

public void setStudentServices(StudentServices studentServices) {
this.studentServices = studentServices;
}
@RequestMapping("showStudent")
public String showStudents(Model model,HttpServletRequest request){
String currentPage = request.getParameter("currentPage")==null?"0": request.getParameter("currentPage");
long studentCount = studentServices.getStudentCount();
int pageSum = (int) (studentCount%20 == 0?studentCount/20:studentCount/20+1);
if(Integer.parseInt(currentPage)>=0&&Integer.parseInt(currentPage)<pageSum){
List<Student> students = studentServices.queryAll(Integer.parseInt(currentPage),20,pageSum);
model.addAttribute("students", students);
request.setAttribute("studentCount", studentCount);
request.setAttribute("currentPage", currentPage);
request.setAttribute("pageSum", pageSum);
return "showInfos/showStudent";
}else{
return "errorPage/showError";
}
}
}

这是JSP
<body>
<div class="container">
<div class="row">
<div class="zeng"><span id="zeng">新增</span></div>
<div class="find">
<div id="selectDiv">
<select id="id_1" style="width:110px">
<option value="">----查询条件----</option>
<option value="stuid">序号</option>
<option value="name">名字</option>
<option value="age">年龄</option>
<option value="address">地址</option>
<option value="add_date">时间</option>
</select>
<input type="text" id="condition" />
<input type="button" value="查询" id="select" />
</div>
</div>
<table class="table table-hover">
<tr class="thead">
<td>学生编号</td>
<td>学生姓名</td>
<td>学生性别</td>
<td>学生年龄</td>
<td>学生地址</td>
<td>学生生日</td>
<td>删除学生</td>
<td>修改学生</td>
</tr>
<c:forEach items="${students }" var="stu">
<fmt:formatDate value="${stu.add_date }" var="bir" pattern="yyyy年MM月dd日"/>
<tr>
<td>${stu.stuid }</td>
<td>${stu.name }</td>
<td>${stu.sex }</td>
<td>${stu.age }</td>
<td>${stu.address }</td>
<td>${bir }</td>
<td><a href="${pageContext.request.contextPath}/studentController/deleteStudent?stuid=${stu.stuid }">删除学生</a></td>
<td><a href="${pageContext.request.contextPath}/studentController/showSingle?stuid=${stu.stuid}">修改学生</a></td>
</tr>
</c:forEach>
</table>
<p>
<a href="studentController/showStudent?currentPage=0">首页</a>
<a href="studentController/showStudent?currentPage=${currentPage-1}">上页</a>
<a href="studentController/showStudent?currentPage=${currentPage+1}">下页</a>
<a href="studentController/showStudent?currentPage=${pageSum-1}">末页</a>
<span>共<< <label>${pageSum}</label> >>页</span>
<span>当前第<a href="studentController/showStudent?currentPage=${currentPage-1}"><<</a> <label>${currentPage+1}</label>
<a href="studentController/showStudent?currentPage=${currentPage+1}">>></a>页</span>
</p>

</div>
</div></body>

这是完成JSP展示数据库的数据,其他的类我就不写了。希望能帮到你
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式