注册 登录
编程论坛 J2EE论坛

jsp页面调用java类的问题。

piaoxue 发布于 2011-11-30 12:36, 3422 次点击
首先 我有一个类ListSql 里面有 id、name、age 分别都有get和set方法。
现在我的一个jsp页面是一个表单,代码属下
<form id="form1" name="form1" method="post" action="Listsql.jsp">
                <%
ListSql listsql = new ListSql();
listsql.setId("id");
listsql.setName("name");
listsql.setAge("age");
listsql.setTable("table");
%>
            表名
            <input name="table" type="checkbox" id="table" value="table" />
            <hr />
            字段一
            <input name="id" type="checkbox" id="id" value="id" />
            字段二
            <input name="name" type="checkbox" id="name" value="name" />
            字段三
            <input name="age" type="checkbox" id="age" value="age" />
            <hr />
            <input type="submit" name="button" id="button" value="提交" />
        </form>
然后我想点击提交的时候,传给java类,然后从这个类中再获取出来显示到领一个jsp页面,代码如下:
<%
ListSql listsql = new ListSql();
String id = "";
String name = "";
String age = "";
String table = "";
//ID = request.getParameter(listsql.getId());
id = listsql.getId();
name = listsql.getName();
age = listsql.getAge()
table = listsql.getTable()
%>
<%=id %>、<%=name %>


但是ID 和 name 都不能输出  是为什么?  请高手解答一下。谢谢
5 回复
#2
twqllq9884952011-11-30 18:45
其实没有必要这样,你只要将类ListSql 导入到Listsql.jsp,具体如下
<form id="form1" name="form1" method="post" action="Listsql.jsp">
            表名
            <input name="table" type="checkbox" id="table" value="table" />
            <hr />
            字段一
            <input name="id" type="checkbox" id="id" value="id" />
            字段二
            <input name="name" type="checkbox" id="name" value="name" />
            字段三
            <input name="age" type="checkbox" id="age" value="age" />
            <hr />
            <input type="submit" name="button" id="button" value="提交" />
        </form>
然后我想点击提交的时候,传给java类,然后从这个类中再获取出来显示到领一个jsp页面,代码如下:
                <%
ListSql listsql = new ListSql();
listsql.setId("id");
listsql.setName("name");
listsql.setAge("age");
listsql.setTable("table");
%>

<%
ListSql listsql = new ListSql();
String id = "";
String name = "";
String age = "";
String table = "";
//ID = request.getParameter(listsql.getId());
id = listsql.getId();
name = listsql.getName();
age = listsql.getAge()
table = listsql.getTable()
%>
<%=id %>、<%=name %>

#3
lucky5635912011-12-01 09:16
调用类直接import
#4
piaoxue2011-12-21 15:34
哦  明白了  直接把传过来的值进行set就可以了,需要的时候,get出来就Ok啦   谢谢上面的兄弟了。 自己脑筋不打弯了  呵呵!
#5
jfei2011-12-27 11:56
呵呵,没有数据
#6
udjhrt2012-02-04 14:48
还真厉害呢
1