本文用到了三个jsp,名称分别为user1.jsp,user2.jsp,user_All.jsp 本案例是将user1.jsp和user2.jsp动态引入到user_All.jsp用到了<jsp:include page="user1.jsp" flush="false"/>
想要实现效果,当点击jsp1按钮的时候就显示user1.jsp页面,当点击jsp2按钮的时候就显示user2.jsp页面,
user1.jsp代码
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="/WEB-INF/eip-xform.tld" prefix="xform"%>
<%@ include file="/resource/jsp/list_top.jsp"%>
<html>
<body>
<div id="a">
<div>我是总的user one jsp</div>
<table>
<tr>
<td>姓名</td>
<td>年龄</td>
</tr>
<tr>
<td>${user.name}</td>
<td>${user.age}</td>
</tr>
</table>
</div>
</body>
</html>
user2.jsp代码
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="/WEB-INF/eip-xform.tld" prefix="xform"%>
<%@ include file="/resource/jsp/list_top.jsp"%>
<html>
<head>
</head>
<body>
<div id="b">
<div>我是总的user second jsp</div>
<table>
<tr>
<td>性别</td>
<td>婚否</td>
</tr>
<tr>
<td>${user.sex}</td>
<td>${user.marray}</td>
</tr>
</table>
</div>
</body>
</html>
user_All.jsp代码
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="/WEB-INF/eip-xform.tld" prefix="xform"%>
<%@ include file="/resource/jsp/list_top.jsp"%>
<html>
<head>
<style>
</style>
<script type="text/javascript">
function changeModul(num){
document.getElementById("b").style.display="none";
document.getElementById("a").style.display="none";
document.getElementById(num).style.display="";
}
</script>
</head>
<body οnlοad="test();">
<div>我是总的jsp</div>
<div>
<input type="button" οnclick="changeModul('a');" value="jsp1"/>
<input type="button" οnclick="changeModul('b');" value="jsp2"/>
</div>
<div id="user1"><jsp:include page="user1.jsp" flush="false"/></div>
<div id="user2"><jsp:include page="user2.jsp" flush="false"/></div>
</body>
</html>
本人开始时遇到的问题:刚开始做,想用id值user1和user2来控制,后来,进过查找资料,得知<jsp:include page="user1.jsp" flush="false"/>是在服务器端执行的,而写的脚本实在浏览器端执行的,所以无法实现本人目的,
解决问题:经过分析,就将id分别写到了user1.jsp和usr2.jsp页面中,然后再在user_All.jsp页面中去取id值进行控制,完成效果,
java代码entity
package com.df.eip.hr.supplier.domain;
public class User {
private String name;
private int age;
private String sex;
private String marray;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public String getMarray() {
return marray;
}
public void setMarray(String marray) {
this.marray = marray;
}
}
java Action
package com.df.eip.hr.supplier.actions;
import com.df.eip.hr.supplier.domain.User;
public class UserAction {
private User user;
public String execute(){
user = new User();
user.setName("李建行");
user.setMarray("否");
user.setAge(23);
user.setSex("男");
return "success";
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
}