我创建了一个名为“menubar.jsp”的页面,如下所示:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="sj" uri="/struts-jquery-tags"%>
<html>
<head>
<s:head/>
<sj:head/>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
</head>
<body>
<div id='cssmenu'>
<ul>
<li><s:a action="#"><span>Home</span></s:a></li>
<li><s:a action="registerLink"><span>Register</span></s:a></li>
<s:url id="loginClick" value="/loginLink.action"></s:url>
<li><sj:a id="login_click" href="%{loginClick}" targets="mainContent"><span>Login</span></sj:a></li>
<li><s:a action="loginLink"><span>Administration</span></s:a></li>
<li class='last'><s:a action="#"><span>Preferences</span></s:a></li>
</ul>
</div>
</body>
</html>
我在我的 index.jsp 页面中包含了这个页面,如下所示:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link rel="stylesheet" type="text/css" href="style.css" media="all" />
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script>
$(function() {
$("#datepicker").datepicker();
});
</script>
<title>My Air - Home</title>
</head>
<body>
<div id="MainPage">
<jsp:include page="header.jsp"></jsp:include>
<jsp:include page="menubar.jsp"></jsp:include>
<div id="mainContent">
<div id="ContentLeft">
<jsp:include page="search.jsp"></jsp:include>
</div>
<div id="contentRight">
<jsp:include page="topdeals.jsp"></jsp:include>
</div>
</div>
<br>
<jsp:include page="footer.jsp"></jsp:include>
</div>
</body>
</html>
我想要的是,当我单击 LOGIN 链接时,名为 loginPage.jsp 的登录页面应显示在 id 为“mainContent”的 div 中。
struts.xml 文件如下:
<action name="loginLink" class="com.view.LoginAction" method="loginLink">
<result name="loginClicked">/loginPage.jsp</result>
</action>
LoginAction 类中的 loginLink 方法只返回“loginClicked”字符串。我运行了代码并检查了它的来源。那里一切看起来都很好,但是单击登录后,什么也没有发生。我在不同的文件中使用了相同类型的代码。它工作得很好。但这里不是。任何人都可以帮助我,我缺少什么或我应该做些什么来让它工作。提前致谢。
下面的代码也试图做同样的事情,它工作正常。我无法弄清楚,我在第一段代码中做错了什么:
以下是我的父页面 loginSuccess.jsp:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib prefix="s" uri="/struts-tags"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link rel="stylesheet" type="text/css" href="style.css" media="all" />
<title>Login</title>
</head>
<body>
<div id="MainPage">
<jsp:include page="header.jsp"></jsp:include>
<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="mainContent">
<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>
</div>
<jsp:include page="footer.jsp"></jsp:include>
</div>
</body>
</html>
以下是包含一些 ajax 调用并将响应放在 loginSuccess.jsp 的 mainContent div 的子页面 menubaruser.jsp。
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib prefix="sj" uri="/struts-jquery-tags"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<html>
<head>
<s:head/>
<sj:head/>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
</head>
<body>
<div id='cssmenu'>
<ul>
<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>
</body>
</html>
下面给出的是我的 struts.xml 映射:
<action name="profile" class="com.view.ProfileAction" method="showProfile">
<interceptor-ref name="myinterceptorSt" />
<result name="loginSessionNotCreated">/loginPage.jsp</result>
<result name="profile">/profile.jsp</result>
</action>
<action name="editProfileLink" class="com.view.ProfileAction" method="editProfileLink">
<interceptor-ref name="myinterceptorSt" />
<result name="loginSessionNotCreated">/loginPage.jsp</result>
<result name="editProfile">/editProfile.jsp</result>
</action>
<action name="editProfile" class="com.view.EditProfileAction" method="editProfile">
<interceptor-ref name="myinterceptorSt" />
<result name="loginSessionNotCreated">/loginPage.jsp</result>
<result name="profileUpdated">/profileUpdated.jsp</result>
</action>
这段代码工作正常。我在第一个问题中实现了同样的事情。但它不起作用。你能提出什么建议吗?