JAVA代码

来源:互联网 发布:cffps软件下载 编辑:程序博客网 时间:2024/05/22 10:55
package com.action;

import java.sql.ResultSet;
import java.sql.SQLException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.dao.Condb;
import com.form.StudentForm;
import com.form.StudentList;

public class Test extends Action {

    
public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response) 
{
        StudentList studentList 
= new StudentList();
        ActionErrors errors
= new ActionErrors();
        StudentForm sform
=(StudentForm)form;
        String name
=sform.getSname();
        System.out.println(name);
        String age
=sform.getSage();
        String address
=sform.getSaddress();
        Condb conn
=new Condb();
        String sql
="insert into stu values('"+name+"','"+age+"','"+address+"')";
        conn.executeUpdate(sql);
        sql
="select * from stu";
        System.out.println(sql);
        ResultSet rs
=conn.executeQuery(sql);
        
try {
            
while(rs.next()){
                sform.setSname(rs.getString(
"sname"));
                sform.setSage(rs.getString(
"sage"));
                sform.setSaddress(rs.getString(
"saddress"));
            }

        }
 catch (SQLException e) {
            e.printStackTrace();
        }

        System.out.println(
"display----");
        ActionForward forward
=new ActionForward();
            forward
=mapping.findForward("display");
        System.out.println(
"over");
        
return forward;
    }

}