我有一个 Web 应用程序,其中第一页是登录页面,一旦我正确登录,就会显示主页。该页面有一个选项卡式菜单,如果我第一次单击其中一个选项卡,主页面会再次刷新,而不是转到请求的页面。这仅发生在第一个 clic 上。其他时候,一切正常。
我用 Firefox、Chrome 和 IE7 给它发短信,这种行为只发生在 IE7上。为什么会这样?错误可能在哪里?因为我不知道我应该在这里复制哪一段代码来澄清我的问题。
PD:我使用过滤器,主页使用 bean 来填充表格。我也试过<redirect/>
tag in faces-cofig.xml
,它解决了这个问题。但是该页面始终显示登录页面中包含的“无效用户”弹出窗口。最后,我丢弃了它。
更新一些代码
我认为问题不在于主页,因为我将其替换为其他页面并且行为相同...(更新 2)但是使用简单的 html 页面可以正常工作。
登录.xhtml:
<h:form id="login">
<h:outputText value="#{msg['login.user']}"/>
<h:inputText value="#{LogBean.name}" required="true"/>
<h:outputText value="#{msg['login.password']}"/>
<h:inputSecret value="#{LogBean.pass}" required="true"/>
<p:commandButton id="botonAccesoPrim"
value="#{msg['login.enter']}"
action="#{LogBean.checkLog}"
oncomplete="dlg1.show();">
</p:commandButton>
<p:dialog id="popup"
visible="#{LogBean.popup}"
widgetVar="dlg1"
modal="true">
<h:outputText value="Invalid User." />
</p:dialog>
日志豆:
public class LogBean {
private String name;
private String pass;
private String validate = "";
private String popup = "false";
//Getters, setters
public String checkLog() throws Exception {
if (correctLog(md5Final)) {
popup = "false";
validate= "success";
return validate;
}
else {
popup = "true";
validate = "fail";
return validate;
}
}
public boolean correctLog(String md5) throws SQLException {
boolean correct = false;
String sql = "SELECT ...";
String passBBDD = null;
cConexionOracle.conecta();
ResultSet result = OracleConnection.query(sql);
if (!(result.next()))
return correct;
else {
passBBDD = result.getString("pass");
if (md5.equals(passBBDD))
correct = true;
}
OracleConnection.desconect();
return correct;
}
public boolean isLogged () {
return name != null;
}
面孔配置:
<managed-bean>
<managed-bean-name>LogBean</managed-bean-name>
<managed-bean-class>LogBeanClass</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
<managed-bean>
<managed-bean-name>mainBean</managed-bean-name>
<managed-bean-class>MainBeanClass</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
<navigation-rule>
<from-view-id>/HTML/login.xhtml</from-view-id>
<navigation-case>
<from-action>#{LogBean.checkLog}</from-action>
<from-outcome>success</from-outcome>
<to-view-id>/HTML/main.xhtml</to-view-id>
<redirect/>
</navigation-case>
<navigation-case>
<from-action>#{LogBean.checkLog}</from-action>
<from-outcome>fail</from-outcome>
<to-view-id>/HTML/login.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
过滤登录:
public void doFilter (ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
HttpServletRequest req = (HttpServletRequest) request;
HttpServletResponse resp = (HttpServletResponse) response;
if (req.getRequestURI().endsWith("login.jsf")) {
chain.doFilter(req, resp);
return;
}
HttpSession session = req.getSession(false);
if (session != null) {
LogBean BeanConnection = (LogBean) req.getSession().getAttribute("LogBean");
if (BeanConnection != null && BeanConnection.isLogged()) {
chain.doFilter(req, resp);
return;
}
}
resp.sendRedirect(req.getContextPath() + "/HTML/login.jsf");
}
web.xml
<filter>
<filter-name>Filter</filter-name>
<filter-class>FilterLogin</filter-class>
</filter>
<filter-mapping>
<filter-name>Filter</filter-name>
<url-pattern>/HTML/*</url-pattern>
</filter-mapping>
mainBean:(更新 2)
private ArrayList<mainClass> mainList = new ArrayList<mainClass>();
private String name;
//...
//Getters, setters.
@PostConstruct
public void populateMainList() {
String sql = null;
if (name == null) {
sql = "SELECT ...";
}
else
sql = "SELECT ... LIKE '%"+name+"%'";
OracleConnection.connect();
ResultSet result = OracleConnection.query(sql);
try {
while(result.next()){
mainClass main = new mainClass();
main.set...(result.getLong("someProperty"));
mainList.add(main);
}
} catch (SQLException e) {
e.printStackTrace();
}
OracleConnection.disconnect();
}
public ArrayList<mainClass> getMainList() throws SQLException {
return mainList;
}
main.xhtml
<h:inputText id="search" value="#{mainBean.name}"> </h:inputText>
<h:commandButton id ="SubmitSearch" action="#{mainBean.seachButton}"></h:commandButton>
<h:commandButton id ="new" value="New" action="#{sistemaBean.newButton}"> </h:commandButton>
<t:dataTable id="data" rows="1" value="#{mainBean.mainList}" var="item"
width="95%" border="0" align="center" cellpadding="0" cellspacing="0">
<t:column width="42%">
<f:facet name="header">
<h:outputText value="Name"/>
</f:facet>
<h:commandLink value="#{item.shortName}" action="#{detailledMainBean.mainDetail}">
<f:param name="idMain" value="#{item.idMain}"/>
</h:commandLink>
</t:column>
<t:column>
<f:facet name="header">
<h:outputText value="Description"/>
</f:facet>
<h:outputText value="#{item.description}"/>
</t:column>
</t:dataTable>
<t:dataScroller id="scroller" for="data"
paginator="false" paginatorMaxPages="5"
paginatorColumnClass="style"
immediate="true"
pageCountVar="pageCount" pageIndexVar="pageIndex"
disableFacetLinksIfFirstPage="true"
disableFacetLinksIfLastPage="true"
renderFacetLinksIfFirstPage="false"
renderFacetLinksIfLastPage="false"
paginatorRenderLinkForActive="false"
renderFacetsIfSinglePage="false"
displayedRowsCountVar="true">
<f:facet name="previous">
<t:outputText styleClass="style" value=" « Previous | "/>
<t:outputText styleClass="style" value="Page #{pageIndex} / #{pageCount}"/>
</f:facet>
<f:facet name="next">
<t:outputText styleClass="style" value=" | Next »"/>
</f:facet>
</t:dataScroller>
提前致谢。