这个问题有点长,但我觉得它很有趣。请看一下。我有一个名为“Menubaruser.jsp”的jsp,如下所示:
<%@ taglib prefix="sj" uri="/struts-jquery-tags"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<div id='cssmenu'>
<ul>
<s:url id="userhome" value="/login.action?login.username=%{#session.username}&login.password=%{#session.password}"></s:url>
<li><sj:a id="user_home" href="%{userhome}" targets="mainContent"><span>Home</span></sj:a></li>
<%-- <li><s:a action="#"><span>Home</span></s:a></li> --%>
<s:url id="showProfile" value="/profile.action"></s:url>
<li><sj:a id="profile_show" href="%{showProfile}" targets="mainContent"><span>Show Profile</span></sj:a></li>
<s:url id="editProfile" value="/editProfileLink.action"></s:url>
<li><sj:a id="profile_edit" href="%{editProfile}" targets="mainContent"><span>Update Profile</span></sj:a></li>
<s:url id="signout" value="/logout.action"></s:url>
<li><sj:a id="signout" href="%{signout}" targets="mainContent"><span>Sign Out</span></sj:a></li>
<%-- <li class='last'><s:a action="#"><span>Contact Us</span></s:a></li> --%>
</ul>
</div>
实际发生的是,当用户登录时,用户名和密码被设置为会话变量及其值。现在用户可以做任何他想做的事情,比如更新个人资料、显示个人资料等。现在我想要的是当用户点击主页时,用户的主页必须出现,即用户登录时出现的页面。该页面被命名为 loginSuccess。 jsp,对应login.action打开,如下struts.xml所示:
<action name="login" class="com.view.LoginAction" method="checkLogin">
<result name="input">/loginPage.jsp</result>
<result name="loginSuccessUser" type="chain">userHistory</result>
<result name="loginSuccessAdmin">/loginSuccessAdmin.jsp</result>
<result name="loginClicked">/loginPage.jsp</result>
</action>
<action name="userHistory" class="com.view.HistoryAction" method="UserHistory">
<result name="showHistory">/loginSuccess.jsp</result>
</action>
loginSuccess.jsp 包含一些来自用户历史操作的动态内容。我希望点击主页时也会加载内容。现在发生的事情是当用户单击主页时,然后使用我发送的与单击相对应的查询字符串调用操作 login.action,如“menubaruser.jsp”所示,但显示的 o/p 是它没有加载密码字段。它返回“输入”,向我显示密码的服务器端验证错误,因为“需要密码”。
需要渲染的 jsp 名为 loginSuccess.jsp,编码如下:
<%@ taglib prefix="s" uri="/struts-tags"%>
<jsp:include page="menubaruser.jsp"></jsp:include>
<div style="width:898px"><br><center>Welcome Mr. <b><s:property value="#session.name"/> </b></center> </div>
<div id="ajaxdiv">
<div id="ContentLeft">
<jsp:include page="search.jsp"></jsp:include>
</div>
<div id="contentRight">
<jsp:include page="topdeals.jsp"></jsp:include>
</div>
</div>
<br>
<div>
<jsp:include page="userHistoryWidget.jsp"></jsp:include>
</div>
UserHistoryWidget.jsp 如下:
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="sj" uri="/struts-jquery-tags"%>
<div id="searchHeaderHistory">Booking History</div>
<div class="CSSTableGenerator">
<table>
<colgroup>
<col span="1" style="width: 5%;">
<col span="1" style="width: 10%;">
<col span="1" style="width: 8%;">
<col span="1" style="width: 15%;">
<col span="1" style="width: 15%;">
<col span="1" style="width: 6%;">
<col span="1" style="width: 6%;">
<col span="1" style="width: 17%;">
<col span="1" style="width: 18%;">
</colgroup>
<tr>
<td>Ticket ID</td>
<td>Booking Date</td>
<td>Flight ID</td>
<td>From</td>
<td>To</td>
<td>Total Fare</td>
<td>Net Fare</td>
<td></td>
<td></td>
</tr>
<s:iterator value="ticketsList" var="ticket" status="stat">
<tr>
<td align="center"><s:property value="#ticket.tid" /></td>
<td align="center"><s:property value="#ticket.bookingdate" /></td>
<td align="center"><s:property
value="#ticket.scheduleDetails.flightDetails.fid" /></td>
<s:if test="#ticket.flag==3">
<td><s:property
value="#ticket.scheduleDetails.flightDetails.routeDetails.via" /><br>
<s:property value="#ticket.scheduleDetails.via_dep_date" /> <s:property
value="#ticket.scheduleDetails.via_dep_time" />hrs</td>
</s:if>
<s:if test="#ticket.flag==1 ||#ticket.flag==2||#ticket.flag==4">
<td><s:property
value="#ticket.scheduleDetails.flightDetails.routeDetails.source" /><br>
<s:property value="#ticket.scheduleDetails.source_dep_date" /> <s:property
value="#ticket.scheduleDetails.source_dep_time" />hrs</td>
</s:if>
<s:if test="#ticket.flag==1 ||#ticket.flag==2||#ticket.flag==3">
<td><s:property
value="#ticket.scheduleDetails.flightDetails.routeDetails.destination" /><br>
<s:property value="#ticket.scheduleDetails.dest_arr_date" /> <s:property
value="#ticket.scheduleDetails.dest_arr_time" />hrs</td>
</s:if>
<s:if test="#ticket.flag==4">
<td><s:property
value="#ticket.scheduleDetails.flightDetails.routeDetails.via" /><br>
<s:property value="#ticket.scheduleDetails.via_arr_date" /> <s:property
value="#ticket.scheduleDetails.via_arr_time" />hrs</td>
</s:if>
<td align="center"><s:property value="#ticket.fare" /></td>
<td align="center"><s:property value="#ticket.dealFare" /></td>
<td style="width: 150px" align="center">
<s:url id="getPassengers" value="/getPassengers.action">
<s:param name="Tid" value="#ticket.tid" />
</s:url>
<sj:a id="link_%{#stat.index}" href="%{getPassengers}" targets="ajaxdiv" cssClass="orangebuttonsmall">
View Details
</sj:a>
</td>
<td style="width: 150px" align="center">
<s:a action="cancel" id="button1" style="float:left" cssClass="orangebuttonsmall">Cancel Ticket
<s:param name="Tid" value="#ticket.tid"></s:param>
</s:a>
</td>
</tr>
</s:iterator>
</table>
</div>
现在我希望每当这个 loginSuccess.jsp 打开 userHIstoryWidget.jsp 内容时被加载。因此,当我在 menubaruser.jsp 中单击主页时,我希望使用会话中存在的值设置用户名和密码的值来调用“登录”。如果这成功发生,那么由于动作链接,“userhistory”动作被调用并显示 loginSuccess.jsp 以及所需的数据。
问题是,当我发送带有用户名和密码值的查询字符串时,它没有设置密码的值,并且它将密码为空,因此返回“输入”,这使得 loginPage.jsp 带有操作错误“密码为空”。我也尝试在密码中发送一个常量值而不是会话值,但问题仍然存在。它设置了用户名的值,但输入密码失败。
LoginPage.jsp 如下:
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="sj" uri="/struts-jquery-tags"%>
<jsp:include page="menubar.jsp"></jsp:include>
<br><br><br><br><br><br>
<s:form action="login" method="post" theme="css_xhtml" cssClass="form1" style="margin:0 211px">
<div class="searchHeader">LOGIN</div>
<div id="error">
<s:property value="errormsg"/>
</div>
<s:textfield label="Username" name="login.username" />
<s:textfield label="Password" name="login.password" />
<div class="submitButton">
<sj:submit value="SUBMIT" targets="mainContent"/>
</div>
</s:form>
请帮助...