有没有实现mvc模式的例子阿?不用struts 那样实现起来很麻烦,怎么实现 View 和Model的通讯,怎样转换调度,很负责哦struts 很好啊,为什么不用这样成熟的框架呢,全世界都在用他~ 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我现在就是不知道 该怎么把bean的处理结果返回给jsp阿不像struts有配置文件struts里很多细节都封装起来了,先弄懂原始的mvc模式,以后很多问题就容易解决了 ^_^ . 直接看 Struts 源码不就行. 看关于 Struts 的工作过程的一个时序图就知道了.Bean 返回的结果代表一个页面就行了,比如直接返回 /user/startpage.jsp, 把必要的变量放到requestScope 中 ,然后让 Servlet forward 到那个页面去,那个页再去 requestScope 中取.Strus 用一个 配置文件中的 forward 名字代表那个页面了,在请求进来的时候 Servlet 用 xxx.do 找到 ActionMapping 并 把所有的 参数都填到 ActionMapping 对应的 formBean 中,然后用这个 formBean 和 actionMapping 及 request 去调用那个 ActionBean , actionBean 把下一个要去的页面的名字返回给 ActionServlet . ActionServlet 就到那个 actionMapping 中 找到 对应的页面 forward 过去. 我现在的理解是这样的:servlet里面调用javabean进行逻辑处理,生成一个存储结果的bean,再把这个bean放在request对象里.根据情况用RequestDispatcher分发给不同的jsp页面.再在jsp里面usebean?总感觉有点怪怪的,不知道设么样才算好的mvc V:JSPC:ServletM:Jdbc/Hibernate/...完全可以自己控制,根本用不着Struts的,当然用也8错 public class BbsAction extends HttpServlet { private BbsManager bbsManager=new com.test.frame.service.BbsManagerImpl(); public void service(HttpServletRequest req, HttpServletResponse res) { String method = req.getParameter("method"); if (!method.equals("")) try { Class[] param = new Class[] { HttpServletRequest.class, HttpServletResponse.class }; Object paramValues1[] = new Object[] { req, res }; Method meth = getClass().getDeclaredMethod(method, param); meth.invoke(this, paramValues1); } catch (Exception e) { System.out.println("reflect failure:" + method + ":" + e.toString()); } } /** * 查询请求操作 * * @param req * @param res * @throws Exception */ public void searchRequestAction(HttpServletRequest req, HttpServletResponse res){ try { HttpSession mySession = req.getSession(); mySession.setAttribute(Constants.SQL_WHERE, null); mySession.setAttribute(Constants.SQL_ORDER, null); this.getServletContext().getRequestDispatcher( "/servlet/bbs_search.jsp").forward(req, res); } catch (Exception e) { Normal.listLog("Action:searchRequestAction:" + e.toString(), BooleanUtil.parse(MessageResources.get("index.isTestLog"))); } }......} public class BbsAction extends DispatchAction { private BbsManager bbsManager= new BbsManagerImpl(); /** * 查询请求操作 * * @param mapping * @param form * @param req * @param res * @return ActionForward * @throws Exception */ public ActionForward searchRequestAction(ActionMapping mapping, ActionForm form, HttpServletRequest req, HttpServletResponse res) throws Exception { try { req.removeAttribute(mapping.getAttribute()); HttpSession mySession = req.getSession(); mySession.setAttribute(Constants.SQL_WHERE, null); mySession.setAttribute(Constants.SQL_ORDER, null); return (mapping.findForward("success")); } catch (Exception e) { Normal.listLog("Action:searchRequestAction:" + e.toString(), BooleanUtil.parse(MessageResources.get("index.isTestLog"))); throw e; } }这里的struts与上面的servlet实现的功能一模一样,代码也几乎相同.M:可以是一般的jdbc,也可以是hibernate等等 最近在边学便用WEBWORK 效果非常好 求个ssh2的 IoC 框架例子 散粉。。 求助 急!iBatis问题,那位大侠能指导下~~给分 标签中如何将变量赋给属性? 初学者,今天开始接触jdom (初学)请大虾帮忙数据库访问的问题? 怎么设定 jfreechart 曲线图中各条曲线的颜色? 我想写一个操作数据库的批处理类,在jsp页面中可以直接调用的 请教tomcat6和iis集成的问题 真难-----Applet访问Sqlserver200的问题!? 在jsp中把表格导入到Excel中中出现问题,求救!
不像struts有配置文件
struts里很多细节都封装起来了,先弄懂原始的mvc模式,以后很多问题就容易解决了
总感觉有点怪怪的,不知道设么样才算好的mvc
C:Servlet
M:Jdbc/Hibernate/...完全可以自己控制,根本用不着Struts的,当然用也8错
private BbsManager bbsManager=new com.test.frame.service.BbsManagerImpl();
public void service(HttpServletRequest req, HttpServletResponse res) {
String method = req.getParameter("method");
if (!method.equals(""))
try {
Class[] param = new Class[] { HttpServletRequest.class,
HttpServletResponse.class };
Object paramValues1[] = new Object[] { req, res };
Method meth = getClass().getDeclaredMethod(method, param);
meth.invoke(this, paramValues1);
} catch (Exception e) {
System.out.println("reflect failure:" + method + ":"
+ e.toString());
}
} /**
* 查询请求操作
*
* @param req
* @param res
* @throws Exception
*/
public void searchRequestAction(HttpServletRequest req,
HttpServletResponse res){
try {
HttpSession mySession = req.getSession();
mySession.setAttribute(Constants.SQL_WHERE, null);
mySession.setAttribute(Constants.SQL_ORDER, null);
this.getServletContext().getRequestDispatcher(
"/servlet/bbs_search.jsp").forward(req, res);
} catch (Exception e) {
Normal.listLog("Action:searchRequestAction:" + e.toString(),
BooleanUtil.parse(MessageResources.get("index.isTestLog")));
}
}
.
.
.
..
.
}
private BbsManager bbsManager= new BbsManagerImpl();
/**
* 查询请求操作
*
* @param mapping
* @param form
* @param req
* @param res
* @return ActionForward
* @throws Exception
*/
public ActionForward searchRequestAction(ActionMapping mapping,
ActionForm form, HttpServletRequest req, HttpServletResponse res)
throws Exception {
try {
req.removeAttribute(mapping.getAttribute());
HttpSession mySession = req.getSession();
mySession.setAttribute(Constants.SQL_WHERE, null);
mySession.setAttribute(Constants.SQL_ORDER, null);
return (mapping.findForward("success"));
} catch (Exception e) {
Normal.listLog("Action:searchRequestAction:" + e.toString(),
BooleanUtil.parse(MessageResources.get("index.isTestLog")));
throw e;
}
}这里的struts与上面的servlet实现的功能一模一样,代码也几乎相同.
M:可以是一般的jdbc,也可以是hibernate等等