Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Architecture & Framework  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 看Spring附带jpetstore(Spring as web tier)登入过程,请指点
yeafee

javaholder



发贴: 42
积分: 1
于 2005-11-23 16:36 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
今天开始看Spring附带的samples中的jpetstore,我配置的是选用Spring作为web tier.
在index.html页面中,有"shop/signonForm.do",根据petstore-servlet.xml中的配置,

<bean name="/shop/signonForm.do"
class="org.springframework.web.servlet.mvc.ParameterizableViewController">
<property name="viewName" value="SignonForm"/>
</bean>

进入到/WEB-INF/jsp/Spring/SignonForm.jsp页面;然后在SignonForm.jsp中登录Form有action="<c:url value="/shop/signon.do"/>".此后,有几个地方不明白,

<bean name="/shop/signon.do"
class="org.springframework.samples.jpetstore.web.spring.SignonController"> ①

<property name="petStore" ref="petStore"/> ②

</bean>


问题①: SignonController.java主要代码如下:

public ModelAndView handleRequest(HttpServletRequest request,
HttpServletResponse response) throws Exception {
String username = request.getParameter("username");
String password = request.getParameter("password");
Account account = this.petStore.getAccount(username, password);
if (account == null) {
return new ModelAndView("Error", "message",
"Invalid username or password. Signon failed.");
}
else {
UserSession userSession = new UserSession(account);
PagedListHolder myList = new PagedListHolder(this.petStore.getProductListByCategory(account.getFavouriteCategoryId()));
myList.setPageSize(4);
userSession.setMyList(myList);
request.getSession().setAttribute("userSession", userSession);

String forwardAction = request.getParameter("forwardAction");

if (forwardAction != null) {
response.sendRedirect(forwardAction);
return null;
}
else {
return new ModelAndView("index");
  }
}
}

上面的UserSession对象是在从哪里来的呢?找了长久没有所获。Sad
还有forwardAction,那个参数是从SignonForm.jsp中的下边代码处来的??可为什么要用一个if语句呢?不解!!!

<c:if test="${!empty signonForwardAction}">
<input type="hidden" name="forwardAction" value="<c:url value="${signonForwardAction}"/>"/>
</c:if>

---------------------------------------------------------------------------------------------------
问题②:发现在petstore-servlet.xml中有好几处都有:
<property name="petStore" ref="petStore"/>

好像是个引用什么的吧?只是这个petstore在哪里呢?有何用呢?

-------------------------------------------------------
-------------------------------------------------------
问题完毕!
呵呵,刚开始Spring的学习,一上来就碰到这么多的问题了,还请各路不吝指导哇!多谢先!Smile附上 petstore-servlet.xml.

petstore-servlet.xml (4.79k)


yeafee edited on 2005-11-23 16:45

三人行,必有我师焉
敏而好学,不耻三问
学而时习之,不思则罔
..........

话题树型展开
人气 标题 作者 字数 发贴时间
23572 看Spring附带jpetstore(Spring as web tier)登入过程,请指点 yeafee 2759 2005-11-23 16:36
19508 Re:看Spring附带jpetstore(Spring as web tier)登入过程,请指点 yeafee 149 2005-11-23 17:03
20272 Re:看Spring附带jpetstore(Spring as web tier)登入过程,请指点 yeafee 636 2005-11-29 17:04
19381 Re:看Spring附带jpetstore(Spring as web tier)登入过程,请指点 yeafee 19 2005-11-23 17:03
18764 Re:看Spring附带jpetstore(Spring as web tier)登入过程,请指点 floater 409 2005-11-24 02:55
19286 Re:看Spring附带jpetstore(Spring as web tier)登入过程,请指点 yeafee 84 2005-11-24 09:31
19190 Re:看Spring附带jpetstore(Spring as web tier)登入过程,请指点 yeafee 1221 2005-11-24 12:45
19834 Re:看Spring附带jpetstore(Spring as web tier)登入过程,请指点 floater 419 2005-11-24 14:24
19263 Re:看Spring附带jpetstore(Spring as web tier)登入过程,请指点 yeafee 97 2005-11-24 20:33
19199 Re:看Spring附带jpetstore(Spring as web tier)登入过程,请指点 yeafee 379 2005-11-29 11:54
18649 Re:看Spring附带jpetstore(Spring as web tier)登入过程,请指点 floater 457 2005-11-29 12:11

flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923