悠悠楠杉
Flexiframe向jsp中传参示例
场景描述
假设我们有一个JSP页面parent.jsp
,它希望向一个嵌入的iframe传递一些信息,该iframe是一个使用Flex(如Adobe Flex)开发的Web应用。我们希望传递的信息包括:
- 标题(Title)
- 关键词(Keywords)
- 描述(Description)
- 正文(Content)
步骤一:JSP页面(parent.jsp)
首先,在parent.jsp
中,我们需要创建一个iframe并设置其src
属性为Flex应用的URL,同时通过URL参数的形式传递所需的数据。例如:
html
<!DOCTYPE html>
<html>
<head>
<title>Parent Page</title>
</head>
<body>
<iframe id="flexFrame" src="http://example.com/flexApp.html?title=Flex%20Demo&keywords=tech,web,development&description=This%20is%20a%20demo%20of%20passing%20data%20to%20Flex%20from%20JSP.&content=Here%20is%20the%20content%20of%20the%20demo." width="800" height="600"></iframe>
</body>
</html>
步骤二:Flex应用(flexApp.html)
html
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function parseParams() {
var urlParams = new URLSearchParams(window.location.search);
var title = urlParams.get('title');
var keywords = urlParams.get('keywords');
var description = urlParams.get('description');
var content = urlParams.get('content');
// 假设有一个函数renderContent()来处理和显示内容
renderContent(title, keywords, description, content);
}
function renderContent(title, keywords, description, content) {
// 创建Markdown结构的HTML内容,此处为简化示例仅展示基本结构
var htmlContent = `# ${title} \n\nKeywords: ${keywords} \n\n${description} \n\n${content}`;
// 将htmlContent添加到DOM中或其他适当的显示位置
document.getElementById('contentArea').innerHTML = htmlContent;
}
</script>
</head>
<body onload="parseParams()">
<div id="contentArea"></div> <!-- 文章内容将在这里展示 -->
</body>
</html>
这段代码在
注意事项:
- 确保对从URL中获取的数据进行适当的验证和清理,以防止跨站脚本(XSS)等安全风险。
- Flex和现代Web技术的结合越来越少,考虑到Flex的维护和支持状况,如有可能建议使用更现代的Web技术栈(如纯JavaScript、React、Vue等)。