呈现视图java.lang.StringIndexOutOfBoundsException:字符串索引超出范围:0
当我尝试登录我的web应用程序时,我遇到了一个问题,用户没有问题,因为当HQL找到数据时,我可以看到跟踪,因此为了更明显,堆栈跟踪如下所示: 对于应用程序,我使用以下库:呈现视图java.lang.StringIndexOutOfBoundsException:字符串索引超出范围:0,java,jsf,primefaces,servlet-filters,Java,Jsf,Primefaces,Servlet Filters,当我尝试登录我的web应用程序时,我遇到了一个问题,用户没有问题,因为当HQL找到数据时,我可以看到跟踪,因此为了更明显,堆栈跟踪如下所示: 对于应用程序,我使用以下库: Primefaces 3.5 JSF2.1.21 休眠4.0.10 JPA2.0 Tomcat 7.0 abr. 30, 2013 4:25:14 PM com.sun.faces.application.view.FaceletViewHandlingStrategy handleRenderException SEVER
- Primefaces 3.5
- JSF2.1.21
- 休眠4.0.10
- JPA2.0
- Tomcat 7.0
abr. 30, 2013 4:25:14 PM com.sun.faces.application.view.FaceletViewHandlingStrategy handleRenderException SEVERE: Error Rendering View[/pages/protected/index.xhtml] java.lang.StringIndexOutOfBoundsException: String index out of range: 0 at java.lang.String.charAt(Unknown Source) at com.sun.faces.application.view.MultiViewHandler.getResourceURL(MultiViewHandler.java:332) at org.primefaces.renderkit.CoreRenderer.getResourceURL(CoreRenderer.java:76) at org.primefaces.renderkit.OutcomeTargetRenderer.getTargetURL(OutcomeTargetRenderer.java:91) at org.primefaces.component.menu.BaseMenuRenderer.encodeMenuItem(BaseMenuRenderer.java:78) at org.primefaces.component.tieredmenu.TieredMenuRenderer.encodeMenuContent(TieredMenuRenderer.java:104) at org.primefaces.component.tieredmenu.TieredMenuRenderer.encodeSubmenu(TieredMenuRenderer.java:166) at org.primefaces.component.tieredmenu.TieredMenuRenderer.encodeMenuContent(TieredMenuRenderer.java:123) at org.primefaces.component.tieredmenu.TieredMenuRenderer.encodeMenu(TieredMenuRenderer.java:77) at org.primefaces.component.menubar.MenubarRenderer.encodeMarkup(MenubarRenderer.java:52) at org.primefaces.component.menu.BaseMenuRenderer.encodeEnd(BaseMenuRenderer.java:39) at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:881) at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1786) at javax.faces.render.Renderer.encodeChildren(Renderer.java:168) at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:851) at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1779) at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1782) at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1782) at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:439) at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:124) at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120) 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:594) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at com.test.ems2.filter.LoginCheckFilter.doFilter(LoginCheckFilter.java:69) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:164) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:562) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:395) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:250) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source)
EMS2App
主题
蓝天
Facesservlet
javax.faces.webapp.FacesServlet
1.
Facesservlet
*.xhtml
/pages/protected/index.xhtml
javax.faces.PROJECT_阶段
发展
登录检查过滤器
com.test.ems2.filter.LoginCheckFilter
后勤
/EMS2APP/pages/public/login.xhtml
登录检查过滤器
/*
管理员页面过滤器
com.test.ems2.filter.AdminPagesFilter
管理员页面过滤器
/页面/受保护/管理/*
DefaultUserPagesFilter
com.test.ems2.filter.DefaultUserPagesFilter
DefaultUserPagesFilter
/页面/受保护/默认用户/*
faces-config.xml文件
信息
捆
信息
我的抽象过滤器类
public class AbstractFilter {
public AbstractFilter() {
super();
}
protected void doLogin(ServletRequest request, ServletResponse response, HttpServletRequest req) throws ServletException, IOException {
RequestDispatcher rd = req.getRequestDispatcher("/pages/public/login.xhtml");
rd.forward(request, response);
}
protected void accessDenied(ServletRequest request, ServletResponse response, HttpServletRequest req) throws ServletException, IOException {
RequestDispatcher rd = req.getRequestDispatcher("/pages/public/accessDenied.xhtml");
rd.forward(request, response);
}
}
我的LoginCheckFilter类:
public class LoginCheckFilter extends AbstractFilter implements Filter {
private static List<String> allowedURIs;
public void init(FilterConfig fConfig) throws ServletException {
if(allowedURIs == null){
allowedURIs = new ArrayList<String>();
allowedURIs.add(fConfig.getInitParameter("loginActionURI"));
allowedURIs.add("/EMS2App/javax.faces.resource/main.css.xhtml");
allowedURIs.add("/EMS2App/javax.faces.resource/theme.css.xhtml");
allowedURIs.add("/EMS2App/javax.faces.resource/primefaces.js.xhtml");
allowedURIs.add("/EMS2App/javax.faces.resource/primefaces.css.xhtml");
allowedURIs.add("/EMS2App/javax.faces.resource/jquery/jquery.js.xhtml");
allowedURIs.add("/EMS2App/javax.faces.resource/messages/messages.png.xhtml");
allowedURIs.add("/EMS2App/javax.faces.resource/images/ui-icons_2e83ff_256x240.png.xhtml");
allowedURIs.add("/EMS2App/javax.faces.resource/images/ui-icons_38667f_256x240.png.xhtml");
}
}
public void destroy() {
}
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
HttpServletRequest req = (HttpServletRequest) request;
HttpSession session = req.getSession();
if (session.isNew()) {
doLogin(request, response, req);
return;
}
User user = (User) session.getAttribute("user");
if (user == null && !allowedURIs.contains(req.getRequestURI())) {
System.out.println(req.getRequestURI());
doLogin(request, response, req);
return;
}
chain.doFilter(request, response); //error -> row 69
}
}
公共类LoginCheckFilter扩展了AbstractFilter实现过滤器{
私有静态列表允许URI;
public void init(FilterConfig fConfig)抛出ServletException{
if(allowedURIs==null){
AllowedURI=新的ArrayList();
add(fConfig.getInitParameter(“loginActionURI”);
allowedURIs.add(“/EMS2App/javax.faces.resource/main.css.xhtml”);
allowedURIs.add(“/EMS2App/javax.faces.resource/theme.css.xhtml”);
allowedURIs.add(“/EMS2App/javax.faces.resource/primefaces.js.xhtml”);
allowedURIs.add(“/EMS2App/javax.faces.resource/primefaces.css.xhtml”);
allowedURIs.add(“/EMS2App/javax.faces.resource/jquery/jquery.js.xhtml”);
allowedURIs.add(“/EMS2App/javax.faces.resource/messages/messages.png.xhtml”);
allowedURIs.add(“/EMS2App/javax.faces.resource/images/ui-icons_2e83ff_256x240.png.xhtml”);
allowedURIs.add(“/EMS2App/javax.faces.resource/images/ui-icons_38667f_256x240.png.xhtml”);
}
}
公共空间销毁(){
}
public void doFilter(ServletRequest请求、ServletResponse响应、FilterChain链)抛出IOException、ServletException{
HttpServletRequest req=(HttpServletRequest)请求;
HttpSession session=req.getSession();
if(session.isNew()){
多洛金(请求、响应、请求);
返回;
}
User=(User)session.getAttribute(“用户”);
if(user==null&&!allowedURIs.contains(req.getRequestURI())){
System.out.println(req.getRequestURI());
多洛金(请求、响应、请求);
返回;
}
chain.doFilter(请求、响应);//错误->第69行
}
}
文件:/pages/protected/index.xhtml
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core" xmlns:p="http://primefaces.org/ui" >
<h:body>
<ui:composition template="/pages/protected/templates/master.xhtml">
<ui:define name="divMain">
#{bundle.welcomeMessage} :<br/>
</ui:define>
</ui:composition>
</h:body>
</html>
#{bundle.welcomeMessage}:
master.xhtml
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://java.sun.com/jsf/core">
<h:head>
<title>EMS2</title>
<h:outputStylesheet library="css" name="main.css" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</h:head>
<h:body>
<f:view contentType="text/html; charset=UTF-8" encoding="UTF-8" >
<div id="divTop" style="vertical-align: middle;">
<ui:insert name="divTop">
<ui:include src="top.xhtml" />
</ui:insert>
</div>
<div id="divMain">
<p:growl id="messageGrowl" />
<ui:insert name="divMain" />
</div>
<div id="divLeft">
<ui:insert name="divDown">
<ui:include src="down.xhtml" />
</ui:insert>
</div>
<h:outputScript library="javascript" name="jscodes.js" />
</f:view>
</h:body>
</html>
EMS2
down.xhtml
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui">
<h:body>
<ui:composition>
<h:form>
<p>Test test test</p><br />
</h:form>
</ui:composition>
</h:body>
</html>
测试测试
top.xhtml
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui">
<h:body>
<ui:composition>
<div id="topMessage">
<h1>
<h:form>
<p:menubar>
<p:submenu label="Personnes">
<p:menuitem label="Ajouter Personne" url="#"/>
<p:menuitem label="Miss a jour Personne" url="#"/>
</p:submenu>
<p:submenu label="Absences">
<p:menuitem label="Poser des absences" url="#"/>
<p:menuitem label="Validation des absences" url="#"/>
<p:menuitem label="Gestion de absences" url="#"/>
</p:submenu>
<p:submenu label="Pointage">
<p:menuitem label="Saisie des temps" url="#"/>
<p:menuitem label="Validation des temps" url="#"/>
<p:menuitem label="Extration des temps Vers PowerMax" url="#"/>
</p:submenu>
<p:submenu label="Projet/Activite">
<p:submenu label="Activite">
<p:menuitem label="Creer Activite" url="/pages/protected/admin/dialogs/creerActivite.xhtml" />
<p:menuitem label="Miss a jour l'Activite" url="/pages/protected/admin/dialogs/missAJourActivite.xhtml" />
</p:submenu>
<p:submenu label="Projet">
<p:menuitem label="Creer projet" url="/pages/protected/admin/dialogs/creerProjet.xhtml" />
<p:menuitem label="Miss a jour projet" url="/pages/protected/admin/dialogs/missAJourProjet.xhtml" />
</p:submenu>
</p:submenu>
<p:submenu label="Rapport">
<p:menuitem label="Statistique projet" url="#"/>
<p:menuitem label="Statistique diverses" url="#"/>
</p:submenu>
</p:menubar>
#{bundle.loginWelcomeMessage}: #{userMB.user.name} | <p:commandButton value="#{bundle.logOut}" action="#{userMB.logOut()}" ajax="false" style="font-size: 20px;" />
</h:form>
</h1>
</div>
</ui:composition>
</h:body>
</html>
#{bundle.loginWelcomeMessage}:#{userMB.user.name}
我认为错误来自xhtml(/pages/protected/index.xhtml),一个primefaces菜单。。。我们能看看这个文件吗?@AlexandreLavoie是的,我已经添加了index.xhtml文件。请再次查看文章。由于错误看起来像EL中的错误,可能是来自索引中的模板,是否所有使用master.xhtml的页面都存在此错误?如果是的话,就需要看一看了@我已经添加了所有文件.xhtml,请参阅。谢谢exception+stacktrace提示您在某个地方有一个
,URL为空字符串。但是,这在目前提供的代码中不可见。因此,要么您没有运行您认为正在运行的代码(清理/重建/重新部署/重新启动),要么代码中有更多内容。顺便说一句,创建一个只有一个拷贝的、粘贴的、可运行的XHTML文件(很可能是一个托管bean)风格的、完全有价值的SSCE将极大地帮助您(和我们)确定原因,而不是这个代码炸弹,它的主要部分与具体问题无关。