资源简介
*************不要问我是谁。请叫我雷锋!************
代码片段和文件信息
package com.action;
import java.io.*;
import java.util.*;
import com.entity.*;
import com.service.*;
import com.service.impl.*;
import org.apache.commons.fileupload.*;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class AddNewAction extends HttpServlet {
/**
* Constructor of the object.
*/
public AddNewAction() {
super();
}
/**
* Destruction of the servlet.
*/
public void destroy() {
super.destroy(); // Just puts “destroy“ string in log
// Put your code here
}
/**
* The doGet method of the servlet.
*
* 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 {
doPost(request response);
}
/**
* The doPost method of the servlet.
*
* 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 {
request.setCharacterEncoding(“GBK“);
boolean ckUpload = ServletFileUpload.isMultipartContent(request);
String ntid =““;
String ntitle =““;
String nauthor =““;
String nsummary =““;
String ncontent =““;
String npicpath =““;
// request.getParameter(arg0) 不能用
if(ckUpload){
//1. 文件上传
boolean ckFile = true;//文件是否上传成功
try{
DiskFileItemFactory df = new DiskFileItemFactory();
ServletFileUpload sfu = new ServletFileUpload(df);//上传组件
String filePath = request.getServletContext().getRealPath(“upload/“);
System.out.println(“----filePath = “+filePath);
//设置上传文件的大小
//sfu.setSizeMax(sizeMax);
sfu.setFileSizeMax(500*1024*1024);
//解析请求
List flist = sfu.parseRequest(request);
for(FileItem fit : flist){
if(fit.isFormField()){ // 普通组件: textcheckboxradiopassword
//取表单元素的值
if(fit.getFieldName().equals(“ntid“)){
ntid = fit.getString(“GBK“);
}
if(fit.getF
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 1093 2017-04-01 11:48 news\.classpath
文件 1329 2017-04-01 12:05 news\.project
文件 522 2017-04-01 11:48 news\.settings\.jsdtscope
文件 364 2017-04-01 11:48 news\.settings\org.eclipse.jdt.core.prefs
文件 471 2017-04-01 11:48 news\.settings\org.eclipse.wst.common.component
文件 414 2017-04-01 11:48 news\.settings\org.eclipse.wst.common.project.facet.core.xm
文件 49 2017-04-01 11:48 news\.settings\org.eclipse.wst.jsdt.ui.superType.container
文件 6 2017-04-01 11:48 news\.settings\org.eclipse.wst.jsdt.ui.superType.name
文件 4823 2018-10-25 10:41 news\src\com\action\AddNewAction.java
文件 2349 2017-04-11 10:04 news\src\com\action\AddTopicAction.java
文件 2217 2017-04-11 10:11 news\src\com\action\DelTopicAction.java
文件 2725 2017-04-18 08:52 news\src\com\action\IndexAction.java
文件 3244 2017-04-15 09:45 news\src\com\action\LoginAction.java
文件 2303 2017-04-11 10:42 news\src\com\action\OneTopicAction.java
文件 2902 2017-04-11 08:51 news\src\com\action\TestAction.java
文件 2719 2017-04-18 08:50 news\src\com\action\TopicListAction.java
文件 2533 2017-04-11 10:52 news\src\com\action\UpdateTopicAction.java
文件 253 2017-04-07 09:14 news\src\com\dao\impl\ba
文件 981 2017-04-05 21:21 news\src\com\dao\impl\JdbcUtil.java
文件 4032 2017-04-15 11:06 news\src\com\dao\impl\TopicDao.java
文件 787 2017-04-07 09:37 news\src\com\dao\impl\UserDao.java
文件 353 2017-04-15 10:07 news\src\com\dao\ITopicDao.java
文件 151 2017-04-07 09:08 news\src\com\dao\IUserDao.java
文件 2093 2017-03-06 11:42 news\src\com\entity\News.java
文件 437 2017-03-06 11:42 news\src\com\entity\Topic.java
文件 611 2017-03-06 11:42 news\src\com\entity\Users.java
文件 683 2017-04-15 09:42 news\src\com\service\impl\AppUtil.java
文件 696 2017-04-15 11:12 news\src\com\service\impl\TopicService.java
文件 347 2017-04-07 09:44 news\src\com\service\impl\UserService.java
文件 366 2017-04-15 11:11 news\src\com\service\ITopicService.java
............此处省略115个文件信息
评论
共有 条评论