jsp里面引入多个动态jsp

本文用到了三个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;
 }
 
}

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值