zoukankan      html  css  js  c++  java
  • struts1.3中使用DispatchAction的一个问题

    近期做项目发现我们公司的项目是用struts1写的,在多方百度下,总有理解了struts1.3的DispatchAction的使用方法

    一:struts.xml文件的配置

    <?xml version="1.0" encoding="utf-8" ?

    > <!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.3//EN" "http://struts.apache.org/dtds/struts-config_1_3.dtd"> <struts-config> <form-beans> <form-bean name="messageBoardFrom" type="com.jobe23.struts.form.message.MessageBoardForm"> </form-bean> </form-beans> <action-mappings> <action path="/zc/graduate/index" type="com.jobe23.struts.action.message.MessageBoardAction" name="messageBoardFrom" parameter="action"> <forward name="successMsg" path="/zc/graduate/index.jsp" /> <forward name="retention" path="/zc/graduate/retention.jsp" /> </action> </action-mappings> </struts-config>


    二:action的配置

    package com.jobe23.struts.action.message;
    
    import java.io.PrintWriter;
    import java.util.ArrayList;
    import java.util.List;
    
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    import org.apache.struts.action.ActionForm;
    import org.apache.struts.action.ActionForward;
    import org.apache.struts.action.ActionMapping;
    import org.apache.struts.actions.DispatchAction;
    
    import com.jobe23.dao.message.MessageBoardDAO;
    import com.jobe23.entity.message.MessageBoard;
    
    /**
     * 专场留言
     * @author clyao
     * @param mapping
     * @param form
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    public class MessageBoardAction extends DispatchAction {
    	
    	
    	public ActionForward message(ActionMapping mapping, ActionForm form,
    			HttpServletRequest request, HttpServletResponse response)
    			throws Exception {
    		MessageBoard mb = new MessageBoard();
    		MessageBoardDAO msgdao = new MessageBoardDAO();
    		List<MessageBoard> msgList = new ArrayList<MessageBoard>();
    		String mobile = request.getParameter("mobile");
    		String msgContent = request.getParameter("msgContent");
    		String specialTitle = request.getParameter("specialTitle");
    		mb.setMobile(mobile);
    		mb.setMsgContent(msgContent);
    		mb.setSpecialTitle(specialTitle);
    		try {
    			if(mobile==null || mobile.equals(null)){
    				
    			}else{
    				msgdao.save(mb);
    			}
    			msgList = msgdao.findAll();
    			request.setAttribute("msgList", hideMobile(msgList));
    		} catch (Exception e) {
    			e.printStackTrace();
    		}
    		return mapping.findForward("successMsg");
    	}
    }
    特别注意:这里的类必须继承DispatchAction,否则无法跳转到相应的方法


    三:測试一下

    http://localhost:8080/zc/graduate/index.do?

    action=message

    它就会运行相应的message方法


    文章能够写得不够完整。怎样疑问,请留言


  • 相关阅读:
    算法训练 数位分离
    算法训练 薪水计算
    算法训练 整除问题
    算法训练 数对
    pom.xml一个简单配置
    MyBatis3.4.0以上的分页插件错误:Could not find method on interface org.apache.ibatis.executor.statement.StatementHandler named prepare. Cause: java.lang.NoSuchMethodException: org.apache.ibatis.executor.stateme
    MyBatis3-实现MyBatis分页
    mybatis 易百练习笔记
    maven pom.xml配置
    Description Resource Path Location Type The superclass "javax.servlet.http.HttpServlet" was not foun
  • 原文地址:https://www.cnblogs.com/gavanwanggw/p/6798671.html
Copyright © 2011-2022 走看看