日期:2014-05-18  浏览次数:20628 次

jsp中应该像我这样写类的调用结果么?我总觉得这样子不规范,但也不知道应该怎么办
我写一个阅读系统,用的MVC结构,没有用什么框架,就是普通的servlet,我想在一章jsp页面中调用当前登录用户的书签信息,因为是页面刷新就得显示结果,所以我把获取结果的代码直接写在了view层里面,通过调用我写好的model里面,代码如下

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<%
response.setHeader("Pragma", "No-cache");
response.setDateHeader("Expires", -1);
response.setHeader("Cache-Control", "No-store");
String uid=null;
String uname = null;
String path = request.getRequestURI();
uid = "1";
/*try {
uid = (String) session.getAttribute("uid");
} catch (Exception e) {
}*/
try {
uname = (String) session.getAttribute("uname");
} catch (Exception e) {
}
if (uname == null)
response.sendRedirect("userlogin.jsp?jumppath="+path);
%>
<%
readlistdao bookmark = new readlistdao();
readlistinfo rli = new readlistinfo();
ArrayList<readlistinfo> bk = new ArrayList<readlistinfo>();
int flag = 1;
try {
bk = bookmark.findbookmark(uid);
if (bk.size() == 0) {
out.print("这个用户bookmark表里面没东西");
flag = 0;
}
} catch (IndexOutOfBoundsException e) {
System.out.println("arraylist打开异常");
e.printStackTrace();
}
%>

我这样直接在页面中调用会不会增加资源消耗??

另外,我对于controller,就是servlet用处的理解就在于他是对于表单提交的一种处理方式,而model,就是那些自己写的类则是给view层和controller层提供支持的一种方式,不知道我的理解对不对

新手刚接触 麻烦大家了
------解决方案--------------------
model写那些javaBean.jsp写页面显示的内容,后台处理我一般都放在servlet中。当然这是当初学习时候的做法了~