我在jsp页面上,想通过一个自定义标签,给标签传入一个对象的ID,然后通过标签将这个对象查询出来,返回到页面,在页面上获取该对象的各种信息,不知道具体该怎么写,在标签的方法里,我已经把对象查出来了,可是我不知道该怎么返回,在页面上怎么表示

解决方案 »

  1.   

    你只要跟我说在doStartTag方法中怎么返回查到的对象,在页面上怎么接收就行了
    public int doStartTag()throws JspException{
    Module module = new Module();
    ServletContext sContext = pageContext.getServletContext();
    ApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(sContext);
    ModuleService moduleService = (ModuleService) ctx.getBean("moduleService");
    module = moduleService.getModuleById(moduleId);
    //System.out.println(module.getModuleName());
        ...  
      }页面:<hx:outWrite moduleId="5">
      

  2.   

    我要求把以上的module返回,在页面上接收,例如:
    <hx:outWrite moduleId="5">
     <div class="word">${什么.moduleName}</div>
    </div>
      

  3.   

    this.getJspContext().getOut().write(你查出来的对象.toString());
    在你的doTag()方法 完成处理后  在加上上面那句话就可以了 
    页面上你只要写你的标签   注意 你设置标签的属性一定要对应
      

  4.   

    在goStartTag方法中直接使用查询对象,同时将查询的对象显示出来就行了和Servlet的doGet/doPost一样子做
      

  5.   

    在标签方法里包获取的对象通过setAttribute()存到request中,然后在jsp页面中获取该对象不就行了~~
      

  6.   

    我现在是查出来一个实体类,比如说Person对象,person有很多对象,如hight、age,我想在也页面上取得这个person的属性,不一定取哪个,可能取age,也可能取hight,并不是直接把person直接输出到页面上