2018-09-28 20:17
@JFinal 解决了, @Clear一下Login拦截器即可, 以前@clear清除所有了,后续准备全部用上enjoy,慢慢深入,再有问题向您请教,谢谢。
2018-09-28 18:12
@Jfinal
我作了如下测试, 在login Controller中:
setSessionAttr("user", userVO); //登陆成功后设置
System.out.println(getSessionAttr("user")); // 有值输出,现在我想问的是在模板中如何获取这个user值?急呀,项目升级就卡在这里了
System.out.println(getSession().getAttribute("session")); //无值
2018-09-28 16:33
@JFinal 按以上输出测试, session 为null ,难道me.add(new SessionInViewInterceptor(true));没起作用?
setSessionAttr("user", userVO);
那改成模板后, 以上这句也就是说没有生效??没有session, setSessionAttr也就失败了,那为什么程序运行setSessionAttr("user", userVO);没有报错?
2018-09-28 16:09
@JFinal 加了true还是一样呀, 配置放在前面也不行,
public void configInterceptor(Interceptors me) {
me.add(new SessionInViewInterceptor(true));
me.add(new com.demo.Interceptor.LoginInterceptor());
}
[com.jfinal.core.ActionHandler.handle()]: /login
com.jfinal.render.RenderException: com.jfinal.template.TemplateException: "session" can not be null for accessed by "session.user"
Template: "/common/index.html". Line: 16
at com.jfinal.render.TemplateRender.render(TemplateRender.java:62)
at com.jfinal.core.ActionHandler.handle(ActionHandler.java:108)
at com.demo.common.MyContextPathHandler.handle(MyContextPathHandler.java:31)
at com.jfinal.core.JFinalFilter.doFilter(JFinalFilter.java:73)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:261)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:581)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:619)
Caused by: com.jfinal.template.TemplateException: "session" can not be null for accessed by "session.user"
2018-09-27 20:35
@Jfinal , @溪碧旗 放在前面还是不行,什么原因? 我的LoginInterceptor及login方法如下,1.8版本下都是能正常运行的:
public class LoginInterceptor implements Interceptor {
public void intercept(ActionInvocation ai) {
Controller controller=ai.getController();
UserVO userVO=controller.getSessionAttr("user");
if (userVO==null){
controller.redirect("/login.jsp");
}else {
ai.invoke();
}
}
}
public void login(){
System.out.println("login controller");
String name=getPara("user","");
String pwd=getPara("pwd","");
UserView user= UserView.dao.findFirst("select * from v_rs_employee where jobno =? and webpwd=?", name,pwd);
if (user!=null){
UserVO userVO=new UserVO();
userVO.setName(user.getStr("cname"));
userVO.setUsrId(user.getStr("jobno"));
setSessionAttr("user", userVO);
redirect("index.html");
}else{
setAttr("msg", "用户名或密码错误!");
renderHtml("/login.html");
}
}
2018-09-25 23:29
@天朝子民
你的意思是说:
只能 me.setError404View("/common/404.html"); 后缀只能改成html了?