About spring MVC
can we modify form bean?--yes.when you want to use it in page, be like this: Object["{attribute name}"]
can we modify model?--yes, if you add a new attribute with same property name, the old one will be replaced.
example:lets say we want to keep some content when we have to jump to another page:
- we use model.addAttribute to set each attribute in model. (can also through formbean, while then you can not use ${attributeName} directly, have to use formbean["attributeName"]).
- in the page we jumped to, we use <springform:hidden "path"="xxx" value="${xxx}"/> to make the properties stay on page(unvisible)
- we also make sure that those attributes defined in the pojo bean related with the from, so when the form was commitd from second page, we got the attributes from the object.
pay attention1:
if you used a<spring:url value="${path}" var="form_url"><spring:param name="twitle" value="${twitterTitle}"/></spring:url>should avoid using twitle as property of form bean, otherwise, in form bean, this property will be mess like "{perperty value},{mapping string value}"
pay attention2:
you can use same property name in model and form bean, they will not affect each other, once I used secretQuestion in both form bean and model property, to save question code and question lable, so I save both of then don't need to transfer to eachother.
--------------
form use post as method by default, spring mvc controller mathod use get as method by default, that why the form action string not lead the request to the method sometimes.
notes:
the <spring:message code="" param=""> the param should not contain ','. (other punctuation not tested)!!! otherwise the content after the puntuation will be lost!
----------------------
Can not jump to a pulic page from an securated url method, example: mathod a response for url"/resendTokenEmailForm", in the end of this method, should not return "public/resendTokenEmailForm", because it's a unsecurated page, even you call logout mehtod fist. the right way is to call 'return "redirect:/public/resendTokenEmailForm"', to go to the controller method first, then in that method, return "public/resendTokenEmailForm".
when doing this, you can use model.addattribute() to add parameter or user "?emailAddress="+tEmail+"&secretQuestion="+tQes" to transfer the parameters.
what if you do modal.addattribute("email", "abc") and add "?email=abc" at the end of url together? the model.get ("email") will be "abc,abc"
-----------------------------
How to change the mothed of form from default "POST" to "PUT"?
when we use a form to do update, we used the default path like "/mainorders" this is the same path with list and create method. So if we still use "method = RequestMethod.POST" in method mapping annotation, it will duplicated with the create method, if don't set, by default it's a GET, so it a conflict with the list method..... then what we should do is to set it to "method = RequestMethod.PUT". here is how to write in jsp file.
<input type="hidden" value="PUT" name="_method"/>
-----------------------------------------------窗口要用Post参数才能传递
that we must use Post to make sure the parameter defined in URLString can be delievered here. if we use GET, then doesn't work.
and the & in URLString must be &
如何封装多个窗口参数
use <form modelAttribute=”conditions”> in View, And use ( FilterBean conditions作为Controller里方法的参数,整个窗体里的内容就被尽量封装进一个FilterBean实例里传给控制器
--
Sam 03:57 11/07/2014
Spring @t'ransactional annotation doesn't work resons:
--
Sam 06:56 17/11/2019
|
Spring 7大模块:
--
Sam 03:01 28/08/2014
|
jsp 页面语法错误导致的貌似离奇的错误: java.lang.ClassNotFoundException: org.apache.jsp.WEB_002dINF.views.public_.list_005fmore_005fblog_jspx
--
Sam 23:39 19/07/2014
|
spingmvc中 MessageSource的使用 可以在controller中使用 @Inject private MessageSource messageSource;然后用return messageSource.getMessage("SHOW_TO_EVERY_ONE", null, locale);来从资源文件获得字符串。 可是,如果中间进行了Controller跳转,要注意,除了当前的Controller以外的Controller中的@Inject private MessageSource messageSource;可能并没有被赋予正确的实例,从而导致最终不能取出字符串,例如:RemarkController中响应了create remark事件,但是调用了publicController的showDetailTwitter方法显示结果。 目前做法是如果一定要跳转(指调用其他Controller的方法,则避免用到其他Controller中注入的messageSource。
--
Sam 02:42 14/07/2014
|
SpringMVC 中默认支持Theme,如果需要修改:
--
Sam 14:49 13/07/2014
|
SpingMVC Controller中的方法是顺序敏感的? 今天才知道,起因是从创建新留言JSP网页中发送请求到Controller后,发现没有没有进入预期的create方法。 因为前些天临时把Message和Remark并在一起的,当时没有发现找不到或找错方法的现象。 我
唯一的修改是在Roo
生成的create方法上加了一个参数。难道是这个原因??不可能,因为在RemarController里面时是好的。为了确信,把path参数重新改
成指向RemarkController-----仍然是好的,说明不是这个原因,同时说明问题不在网页,而在Controller方面。 MessageController死活看不错异常,就是加了参数后,create方法就进不来,去掉参数,就能进来。 最后才怀疑到在前面的那个list方法,RemarkController中也有个list方法,唯一不同是放在了后面... 于是也挪到后面去,再试-----成功! 说明:spring在Controller中匹配方法是,不是找最最匹配的,而是从上往下找第一个匹配的。 (wait!!! 这么说也不对,例子: url:http://localhost/bigbang/tao会进入第一个方法,http://localhost/bigbang/getImage进入第一个方法,而http://localhost/bigbang/getImage/2234则会进入第二个方法。说明参数层数是个硬坎。即使第二个方法更匹配,但层数不对,就指定会跟第一个方法匹配。 Method1: @RequestMapping(value = "/{spaceOwner}", produces = "text/html") public String index(@PathVariable("spaceOwner") String p1, @RequestParam(value = "page", required = false) Integer p2) { Method2: @RequestMapping(value = "/getImage/{id}") public void getImage(@PathVariable("id") String id,) { 另外,如果第二个方法前插一个 @RequestMapping(value = "/getImage") public void getImage() 那么,urlhttp://localhost/bigbang/getImage就会匹配到这个新插入的方法上。 而如果你输入一个没有匹配的URL,如:http://localhost/bigbang/xyz/eee 那么第一个方法将会把它截获,但是截获后你会发现p1参数的值为“resourceNotFound". ---------------------------------------------------------- 不但要保证RequestMapping 唯一性,还要保证RequestParam数目相同 that not only the @RequestMapping must be the unique one for the URLString, but also the
@RequestParam name and numbers must match the URLstring. what we
still not clear is that is it OK if the URLString contains more parameters than specified? the parameter's sequence matters: <spring:url value="${path}" var="form_url"> <spring:param name="twitterid" value="${twitterId}"/> <spring:param name="refreshTime" value="44"/> </spring:url> goes to the @RequestMapping(params = "twitterid", method = RequestMethod.POST, produces = "text/html")
public String createRemark(@RequestParam(value = "refreshTime",
required = false) String refreshTime, @Valid Remark remark,
BindingResult bindingResult, @RequestParam(value = "twitterid", required
= false) Long pTwitterId, Model uiModel, HttpServletRequest
httpServletRequest) { (which is good!) while <spring:url value="${path}" var="form_url"> <spring:param name="refreshTime" value="44"/> <spring:param name="twitterid" value="${twitterId}"/> </spring:url> goes to: @RequestMapping(produces = "text/html")
public String list(@RequestParam(value = "page", required = false)
Integer page, @RequestParam(value = "size", required = false) Integer
size, Model uiModel)
--
Sam 04:01 11/07/2014
|
如何在Spring项目中配置并使用Quartz? Spring的配置文件如何被Tomcat找到? Tomcat的没有应用程序下有个WEB-INF目录,里面有个web.xml文件,里面有个注释:<!-- Context Configuration locations for Spring XML files -->这一个部分的param name value对就告诉了Tomcat到哪里去找xml文件,把里面的内容都读到hashmap里去:<param-name>contextConfigLocation</param-name> <param-value>.......<> Quartz如何加入到项目里? 在任意一个web.xml能找到的文件里定义 <bean id="schedulerFactoryBean" class="org.springframework.scheduling.quartz.SchedulerFactoryBean"> <property name="triggers"> <list> <ref local="refreshSessionTrigger"/> </list></property> </bean> <bean id="refreshSessionTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerBean"> <property name="jobDetail" ref="refreshSessionJobDetail" /> <property name="startDelay"> <value>0</value> </property> <property name="repeatInterval"> <value>60000</value> </property></bean> <bean id="refreshSessionJobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"> <property name="targetObject"> <ref bean="refreshSessionJobProcessor" /> </property> <property name="targetMethod"> <value>refreshSession</value> </property></bean> <bean id="refreshSessionJobProcessor" class="com.caesarsint.box.job.RefreshSessionJobProcessor"></bean> 然后,RefreshSessionJobProcessor类中的ratgetMethod:refreshSession就会被执行了。 注意,这些bean要倒着写(因为确保每个用到的bean都是事先定义过的) 其他 quartz 2.1.6 does not work with spring 3.1 well (if we user 2.1.6, we can not user cronTrigger though we can still use SimpletriggerFactoryBean to set repeatInterval) because the parent class of class org.springframework.scheduling.quartz.CronTriggerBean was a class in quartz.jar with the nameCronTrigger. while now, the "CronTrigger" is changed into an interface by quartz!
--
Sam 02:41 11/07/2014
|
如何在spring Security中配置单点登录
--
Sam 02:40 11/07/2014
|
springsecurity,如何获得当前用户? java代码中: @Inject private UserContextService userContextService; userContextService.getCurrentUserName()
--
Sam 02:40 11/07/2014
|