在过去的几天里,我一直在努力使用我的网络应用程序的登录部分.我已经到了能够在tomcat上使用JDBCRealm(通过从sql server数据库中读取用户)成功验证用户的程度.现在我想在用户的帐户被阻止时发送某种反馈,或者当凭据不正确时,这就是我现在被困住的地方.
我想用这个:
try {
request.login(request.getParameter("user"), request.getParameter("pass"));
} catch (ServletException se) {
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("Wrong Username/Password combination"));
log(se.getMessage());
}
Run Code Online (Sandbox Code Playgroud)
但FacesContext.getCurrentInstance()始终返回null ..
在做了一些研究后,我发现请求必须来自位于/ faces中的页面,以便调用FacesServlet并初始化FacesContext(至少这是我所理解的).
所以我将登录页面移动到Web Pages文件夹中名为faces的新文件夹.但现在每次我尝试调用login.xhtml页面时,都会收到此错误:
/login.xhtml Not Found in ExternalContext as a Resource
Run Code Online (Sandbox Code Playgroud)
这是堆栈跟踪:
com.sun.faces.context.FacesFileNotFoundException: /login.xhtml Not Found in ExternalContext as a Resource
at com.sun.faces.facelets.impl.DefaultFaceletFactory.resolveURL(DefaultFaceletFactory.java:232)
at com.sun.faces.facelets.impl.DefaultFaceletFactory.resolveURL(DefaultFaceletFactory.java:273)
at com.sun.faces.facelets.impl.DefaultFaceletFactory.getFacelet(DefaultFaceletFactory.java:201)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.buildView(FaceletViewHandlingStrategy.java:764)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:100)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:410)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
at …
Run Code Online (Sandbox Code Playgroud) 我有以下LINQ to实体查询(使用odp.net):
Dim query = from Elemento in X.VIEW where Elemento.code = "10" Select New With {Elemento.code, .Time = Elemento.Time.ToString("HH:mm")} query.ToList()
代码会抛出该ToList()
方法的异常:
LINQ to Entities does not recognize the method 'System.String ToString()'
我已经阅读了所有关于此的内容,但还没有找到一个简单的解决方法.
Lazyberezovsky有正确的答案,我之前无法让它工作,因为我这样做:
Dim query = (from Elemento in X.VIEW where Elemento.code = "10" Select New With {Elemento.code, Elemento.Time}).ToList Dim query2 = from elemento in query Select New With {elemento.code, TIME = elemento.Time.ToString("HH:mm")} Dim result = query2.ToList()
但这不起作用,显然你必须一步到位.