0

我正在输入以下网址并添加以下内容

?用户ID=XBBBB

我试图通过 index.jsp 到 proauth.xhtml 并进入我的 ProfileAuthorizationBean.java 的支持 bean 的 XBBBB 的用户 ID。

代码一直通过,但是在 index.jsp 之后 UserID=XBBBB 参数丢失了。IOW,index.jsp 中的 System.out 正在将 XBBBB 打印到控制台,我相信正在转发到 proauth.xhtml。当我在 ProfileAuthorizationBean 中使用 HttpServletRequest 时,UserID 的参数不存在。

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="ISO-8859-1" %>
<html>
<head></head>
<body></body>
<%
request.setCharacterEncoding("UTF-8");
String UserID = request.getParameter("UserID");
if (UserID != null) {
   System.out.println(UserID);
   response.sendRedirect("proauth.xhtml?UserID=" + UserID);
}
%>
</html>


<!DOCTYPE html>
<html xmlns:h="http://java.sun.com/jsf/html"
  xmlns:f="http://java.sun.com/jsf/core"
  xmlns:ui="http://java.sun.com/jsf/facelets"
  xmlns:p="http://primefaces.org/ui"
  xmlns:c="http://java.sun.com/jsp/jstl/core">
 <h:head>
  <link rel="stylesheet" type="text/css" href="themes/local/tinstyle.css"/>
 </h:head>
 <script type="text/javascript">
 function doSubmit() {
  document.getElementById('proAuthForm:proAuthBtn').click();
 }
 </script>
 <h:body onload="doSubmit()">
 <h:form id="proAuthForm">
<p:commandButton id="proAuthBtn" value="" action="#{profileAuthorizationBean.doProfileAuth}" ajax="false" />  
 </h:form>
 </h:body>
</html>


public String doProfileAuth() {
 String retValue = "landingPage";
 try {

   HttpServletRequest request = (HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest();
   System.out.println(request.getParameter("UserID"));
.
.
.
} catch (Exception e) {
}
}
4

0 回答 0