【发布时间】:2024-05-23 04:25:01
【问题描述】:
我正在尝试实现用户帐户页面。在页面中,当我单击左侧的链接时,例如“搜索用户”、“准备笔记”等。我想在右侧的 div 中包含相关的 jsp 页面,如下所示。
我首先使用 iframe 代替 div,但我可以将会话对象属性传递给 iframe 中加载的页面,因为 iframe 发送单独的 http 请求。
我想在右侧 div 中使用 jsp:include 而不是 iframe 来显示相应的 jsp 页面。新的目标 div 将与 iframe 相同。
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<link rel="stylesheet" href="${pageContext.request.contextPath}/css/bootstrap.min.css">
<script src="${pageContext.request.contextPath}/js/jquery-1.11.2.min.js"></script>
<script src="${pageContext.request.contextPath}/js/bootstrap.min.js"></script>
<style>
#dashboard-iframe{
border: 1px solid gray;
height: 200px;
width: 200px;
}
</style>
<script type="text/javascript">
//jquery function i tried
(document).ready(function() {
$("#searchUser").click(function(){
$("#dashboard-iframe").load("${pageContext.request.contextPath}/searchuser");
});
});
//plain javascript
function searchClick(){
document.getElementById('dashboard-iframe').innerHTML=
"<jsp:include page="${pageContext.request.contextPath}/searchuser">";
}
</script>
</head>
<body onload="hidedisplay()">
<div class="panel panel-default">
<div class="panel-body">
<div class="list-group pull-left">
<a id="searchUser" onclick="searchClick()" href="#" class="list-group-item" target="dashboard-iframe">
<span class="glyphicon glyphicon-search"></span> Search Users
</a>
<a href="${pageContext.request.contextPath}/message_board" target="dashboard-iframe" class="list-group-item">
<span class="glyphicon glyphicon-inbox"></span> Message Board
</a>
<a href="${pageContext.request.contextPath}/prepare_notes" class="list-group-item" target="dashboard-iframe">
<span class="glyphicon glyphicon-list-alt"></span> Prepare Notes
</a>
<a href="${pageContext.request.contextPath}/UploadYourFile" target="dashboard-iframe" class="list-group-item">
<span class="glyphicon glyphicon-upload"></span> Share File
</a>
<a href="${pageContext.request.contextPath}/ComposeMessage" target="dashboard-iframe" class="list-group-item">
<span class="glyphicon glyphicon-envelope"></span> Compose Message
</a>
<a href="${pageContext.request.contextPath}/edit-profile" target="dashboard-iframe" class="list-group-item">
<span class="glyphicon glyphicon-pencil"></span> Edit Profile
</a>
<a href="${pageContext.request.contextPath}/connected-users" target="dashboard-iframe" class="list-group-item">
<span class="glyphicon glyphicon-link"></span> Connected Users
</a>
</div><!-- list-group end -->
</div>
</div>
<div id="dashboard-iframe">
<!-- Where i want to display the pages -->
</div>
</body>
</html>
我尝试了一些 jquery 以及普通的 javascript,但它不起作用。我很早就需要解决方案......对不起。请帮忙。
【问题讨论】:
标签: javascript jquery html jsp iframe