AbstractAction

本文介绍了一个基于Struts框架的抽象Action类实现,该类通过反射机制动态调用具体的方法,实现了灵活的请求处理流程。文章详细展示了如何通过继承`Action`类创建自定义的`AbstractAction`类,并利用`Logger`进行调试信息记录。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

package com.eb.common;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;


public abstract class AbstractAction extends Action{

 private DC dc = null;
 private Logger logger = Logger.getLogger(AbstractAction.class);
 
 public ActionForward execute(ActionMapping actionMapping,
   ActionForm actionForm,HttpServletRequest request,
   HttpServletResponse response) throws Exception{
  
  logger.debug("come into method execute()");
  
  dc = new DC();
  ActionForward nextpage=null;
  nextpage = processExecute(actionMapping,(AbstractActionForm)actionForm,request,response,dc);
  return nextpage;
 }
 /*
  *
  */
 private ActionForward processExecute(ActionMapping actionMapping,
   AbstractActionForm form,HttpServletRequest request,
   HttpServletResponse response,DC dc) throws Exception{
  logger.debug("come into processExecute()");
  
  String forward = (String)this.getClass().getMethod(request.getParameter( "do" ),new Class[] {
   AbstractActionForm.class,
   HttpServletRequest.class,
   HttpServletResponse.class,
   DC.class } ).invoke(this,new Object[] { form,
   request,response,dc } );
  return actionMapping.findForward(forward);
 }
 protected abstract AbstractVO Form2VO(AbstractActionForm form) throws Exception;
 protected abstract AbstractActionForm VO2Form(AbstractVO vo) throws Exception;
 protected abstract DC callEJB(DC dc) throws Exception;
}
 

修改这段代码实现选择表格一行信息删除package frame; import javax.swing.; import java.awt.; import java.awt.event.ActionEvent; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.SQLException; //添加页面 public class EditDialog extends BaseDialog{ DataChangelisenter dataChangelisenter; public void setDataChangelisenter(DataChangelisenter dataChangelisenter) { this.dataChangelisenter = dataChangelisenter; } @Override public void init() { setLayout(new FlowLayout()); //布局 setTitle("修改图书信息"); JPanel jp0=new JPanel(); JLabel l0 = new JLabel("id"); JTextField t0 = new JTextField(); t0.setPreferredSize(new Dimension(300,30)); jp0.add(l0); jp0.add(t0); JPanel jp1=new JPanel(); JLabel l1 = new JLabel("书名"); JTextField t1 = new JTextField(); t1.setPreferredSize(new Dimension(300,30)); jp1.add(l1); jp1.add(t1); JPanel jp2=new JPanel(); JLabel l2 = new JLabel("作者"); JTextField t2 = new JTextField(); t2.setPreferredSize(new Dimension(300,30)); jp2.add(l2); jp2.add(t2); JPanel jp3=new JPanel(); JLabel l3 = new JLabel("分类"); JTextField t3 = new JTextField(); t3.setPreferredSize(new Dimension(300,30)); jp3.add(l3); jp3.add(t3); JPanel jp4=new JPanel(); JLabel l4 = new JLabel("出版社"); JTextField t4 = new JTextField(); t4.setPreferredSize(new Dimension(300,30)); jp4.add(l4); jp4.add(t4); JPanel jp5=new JPanel(); JLabel l5 = new JLabel("数量"); JTextField t5 = new JTextField(); t5.setPreferredSize(new Dimension(300,30)); jp5.add(l5); jp5.add(t5); add(jp0); add(jp1); add(jp2); add(jp3); add(jp4); add(jp5); JButton b1 = new JButton("保存"); b1.setPreferredSize(new Dimension(150,30)); b1.addActionListener(new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { String id = t0.getText(); String sname = t1.getText(); String author = t2.getText(); String classify = t3.getText(); String press = t4.getText(); String quantity = t5.getText(); Connection con = DBUtil.getConnect(); String sql = "UPDATE tushu SET sname=?,author=?,classify=?,press=?,quantity=? WHERE id=?"; try { PreparedStatement ps = con.prepareStatement(sql); ps.setString(1,sname); ps.setString(2,author); ps.setString(3,classify); ps.setString(4,press); ps.setString(5,quantity); ps.setString(6,id); int result = ps.executeUpdate(); if (result>0){ JOptionPane.showMessageDialog(EditDialog.this,"修改成功"); // new StudentFrame(); dataChangelisenter.dataChange(); dispose(); }else { JOptionPane.showMessageDialog(EditDialog.this,"修改失败"); } } catch (SQLException throwables) { throwables.printStackTrace(); } } }); add(b1); } }
05-25
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值