j2ee中 xxx.class文件 和相关联的 xxx.jsp页面 之间如何传递参数

来源:互联网 发布:淘宝社区 编辑:程序博客网 时间:2024/06/09 21:01

1.  类文件向 .jsp页面 传递参数

 

例子 :把 类文件中的变量 file1 传递到 .jsp页面

类文件中如下

String file1[]="hello";request.setAttribute("file1", file1);


 

.jsp页面如下

 String[] File = (String[])request.getAttribute("file1");


这样 类文件中的 变量file1的值就传递到.jsp页面中的变量File中

 

 

2..jsp页面向 类文件中传递参数(传递的是隐藏变量,不是页面中有用户通过操作传递的)

 

在 .jsp页面中如下

<input type="hidden" name="reporttype" value="2"/>


在 类文件中如下

String s = (String) request.getParameter(reporttype);

 

这样 .jsp页面中的reporttype的值就传递到 相关类文件中

 

原创粉丝点击