⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 chinamobilerccservlet.java

📁 新东方软件开发项目
💻 JAVA
字号:
package com.mobile.controller;

import java.io.IOException;
import java.io.PrintWriter;

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

import com.jspsmart.upload.File;
import com.jspsmart.upload.Files;
import com.jspsmart.upload.Request;
import com.jspsmart.upload.SmartUpload;
import com.mobile.bean.TMobiles;
import com.mobile.dao.TMobileDAO;

public class ChinaMobileRCCServlet extends HttpServlet {

	
	
	public ChinaMobileRCCServlet() {
		super();
	}

	/**
	 * Destruction of the servlet. <br>
	 */
	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}

	/**
	 * 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 {

		 request.setCharacterEncoding("GBK");
			response.setContentType("text/html;charset=GBK");
		response.setContentType("text/html");
		String flag=request.getParameter("flag");
		System.out.println("come in");
		System.out.println(flag+"111111111111");
		 if ("submitNumber".equals(flag))
			{
			   System.out.println(flag);
				TMobiles tm = new TMobiles();
				TMobileDAO tmd = new TMobileDAO();
				String cardType = request.getParameter("num");
				String startNum = request.getParameter("begin");
				long startNum1 = Long.valueOf(startNum).longValue();
				String endNum = request.getParameter("end");
				long endNum1 = Long.valueOf(endNum).longValue();
				int ret = tmd.insertTMobile(cardType, startNum1, endNum1);
			System.out.println("ret");
					if (ret != 0)
						 response.sendRedirect("insert_succ.jsp");
				
			}
			if ("submitNumberFromFile".equals(flag))
			{
		
				SmartUpload su = new SmartUpload();
				System.out.println(flag+"111111111111");
				// 传入相关参数,完成smartupload初始化
				su.initialize(this.getServletConfig(), request, response);
	
				TMobileDAO tb=new TMobileDAO();
				
				// 上传文件
				try{
			
				//su.setAllowedFilesList("txt");
					su.setDeniedFilesList("txt");
					
					// 相当于读取文件流
					su.upload();
					
					Request req = su.getRequest();
					String str = req.getParameter("myfile");
					System.out.println(str);
					
					
					Files files = su.getFiles();
					int count = files.getCount();			
								
					// 循环对每一个文件进行处理
					for(int i=0;i<count;i++){
						// 得到每一个文件
						File f = files.getFile(i);
						if(!f.isMissing()){
							f.saveAs("e:/resource/"+f.getFileName(),File.SAVEAS_VIRTUAL);
							String mypath="e:/resource/"+f.getFileName();
							tb.inputNumFromFile(mypath);
						}
					    
					}
					
					
					
					
				}catch(Exception e){
					e.printStackTrace();
				}		
			}
				
				
				
				
				
				
			}
	       
	       
	       

	/**
	 * The doPost method of the servlet. <br>
	 * 
	 * This method is called when a form has its tag value method equals to
	 * post.
	 * 
	 * @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 doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
           
	
		this.doGet(request, response);
	}

	/**
	 * Initialization of the servlet. <br>
	 * 
	 * @throws ServletException
	 *             if an error occurs
	 */
	public void init() throws ServletException {
		// Put your code here
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -