如何在JSP或struts中显示gridview表并给出编辑按钮 [英] how to display gridview table and give edit button in JSP or struts
问题描述
请指导我想要代码只想在浏览器上用编辑按钮显示表格。
如果我点击编辑就应该更改。
这一切都在JSP中或struts with mysql。
哪个更容易获得JSP或struts?
please guide i want code just want to show table on browser with edit button.
if i click on edit it should be change.
this all be in JSP or struts with mysql.
which get more easy JSP or struts?
推荐答案
1。为网格视图创建一个Java bean类
例如:
public class Student {
private String studentid,studentname,classname;
公共学生(String studentid,studentname,classname){
this.studentid = studentid;
this.studentname = studentname;
this.classname = classname;
}
添加getter方法
}
2.创建动作支持班
创建bean对象(学生)
从数据库中选择数据
将数据存储到结果集
将这些数据添加到bean
示例:
公共类ActionSupportClass扩展了ActionSupport
{
private List< student> student = new ArrayList<>();
//学生的getter方法
public String studentdetails()
{
//写连接字符串mysql
//写执行查询
// assign结果到ResultSet
while(res.next()){
student.add(新学生(res.getString(1),res.getString(2),res.getString(3)));
}
}
}
3.在jsp页面
1. create a Java bean class for grid view
example:
public class Student{
private String studentid,studentname,classname;
public Student(String studentid,studentname,classname){
this.studentid=studentid;
this.studentname=studentname;
this.classname=classname;
}
getter methods added
}
2. create action support class
create bean object(Student)
select data from database
store data to resultset
add thesse data to bean
example:
public class ActionSupportClass extends ActionSupport
{
private List<student> student=new ArrayList<>();
//getter methods of student
public String studentdetails()
{
//write connection string mysql
//write execute query
// assign result to ResultSet
while(res.next()){
student.add(new Student(res.getString(1),res.getString(2),res.getString(3)));
}
}
}
3. In jsp page
<table>
<tr><th>Student name</th><th>Class</th></tr>
< s:iterator value =requisitionreportstatus =statusxmlns: s =#unknown>
< s:property value =studentname>< s:property value =classname> 详细信息
<s:iterator value="requisitionreport" status="status" xmlns:s="#unknown">
<s:property value="studentname"><s:property value="classname">Details
</table>
4。创建jquery并添加方法viewdetails(action,studentid)
示例
函数viewdetails(action,studentid){<
//添加ajax发布操作并将结果返回为json
}
4. create jquery and add method viewdetails(action,studentid)
example
function viewdetails(action,studentid){
// add ajax post action and return result as json
}
这篇关于如何在JSP或struts中显示gridview表并给出编辑按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!