com.code.servlet

package com.code.servlet;

import java.io.IOException;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

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

import com.domain.bean.TmpBean;
import com.service.impl.CodeSericeImpl;
import com.service.impl.CodeServiceDao;

public class AddConditionServlet extends HttpServlet {

    /**
     * The doGet method of the servlet. <br>
     * 
     * This method is called when a form has its tag value method equals to get.
     * 
     * @param request
     *            the request send by the client to the server
     * @param response
     *            the response send by the server to the client
     * @throws ServletException
     *             if an error occurred
     * @throws IOException
     *             if an error occurred
     */
    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setHeader("Pragma","No-cache"); 
        response.setHeader("Cache-Control","no-cache"); 
        response.setDateHeader("Expires", 0); 
        String referer = request.getHeader("referer");
        if(referer == null){
            response.sendRedirect(request.getContextPath() + "/index.jsp");
            return;
        }
        
        String vallist = request.getParameter("txtcondition");
        String mscript = request.getParameter("txtmscript");
        if (vallist == null || vallist.equals("")) {
            request.getRequestDispatcher("/WEB-INF/jsp/addcontidion.jsp")
                    .forward(request, response);
            return;
        }
        
        if (mscript == null && mscript.equals("")) {
            request.getRequestDispatcher("/WEB-INF/jsp/code.jsp").forward(
                    request, response);
            return;
        }
        if (mscript.contains("**") || mscript.contains("***")
                || mscript.contains("****")) {
            request.getRequestDispatcher("/WEB-INF/jsp/addcontidion.jsp")
                    .forward(request, response);
            return;
        }
        CodeServiceDao ssi = new CodeSericeImpl();
        //mscript remove rule condition.  eg. (n) (o) (p)
                
        mscript = ssi.removeRuleNumber(mscript);
        
        
        TmpBean tpb = (TmpBean) request.getSession().getAttribute("tpb");
        tpb.setGetVarStr(vallist);
        List<String> varlist = ssi.splitVariable2list(vallist);

        LinkedHashMap<String, String> valMap = ssi.varAdd2Map(varlist);        
        
//        Pattern pattern = Pattern.compile("\\.*");
//        Matcher matcher = pattern.matcher(mscript);
//        String str = matcher.replaceAll("</br>");
        
//        System.out.println(str);
        
        tpb.setMscript(mscript);
        tpb.setVarMap(valMap);
        System.out.println(tpb.getVarMap());
        System.out.println(tpb.getMscript());
        request.getRequestDispatcher("/customerVelocityServlet").forward(
                request, response);
    }

    public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        this.doGet(request, response);
    }

}

 

 

package com.code.servlet;

import java.io.IOException;
import java.util.LinkedHashMap;
import java.util.List;

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

import com.domain.bean.TmpBean;
import com.service.impl.CodeSericeImpl;
import com.service.impl.CodeServiceDao;

public class CodeServlet extends HttpServlet {

    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setHeader("Pragma","No-cache"); 
        response.setHeader("Cache-Control","no-cache"); 
        response.setDateHeader("Expires", 0); 
        String referer = request.getHeader("referer");
        if(referer == null){
            response.sendRedirect(request.getContextPath() + "/index.jsp");
            return;
        }
//        String testcase = request.getParameter("testcase");
        String testcontext = request.getParameter("testcontext");
        
        if(testcontext==null||testcontext.equals("")){
            request.getRequestDispatcher("/WEB-INF/jsp/code.jsp").forward(request, response);
            return;
        }
        TmpBean tpb = new TmpBean();
        tpb.setContex(testcontext);
        CodeServiceDao ssi = new CodeSericeImpl();
        
        // variable work*************************************************************
//        List<String> varlist = ssi.splitVariable2list(testcase);
//        
//        LinkedHashMap<String,String> valMap = ssi.varAdd2Map(varlist);
//        tpb.setVarMap(valMap);
        // String varStr = ssi.varAppend(varlist);--will be use by other function
        // *****************************************************************************

        // context after format
        String txtVal = ssi.StrAppend(testcontext);
        txtVal = ssi.formatString(txtVal);
        tpb.setLayout(txtVal);
        request.getSession().setAttribute("tpb", tpb);
    
        request.getRequestDispatcher("/WEB-INF/jsp/addcontidion.jsp").forward(request, response);
    }


    public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        this.doGet(request, response);
    }

}

 

posted @ 2014-04-09 23:55  MrMrCash  阅读(219)  评论(0编辑  收藏  举报