org.apache.catalina.connector.RequestFacade cannot be cast to javax.servlet.Gene

qq_35424597 qq_35424597 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
at com.product.ProductAction.addProduct(ProductAction.java:211)
at com.product.ProductAction.doPost(ProductAction.java:80)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:619)
具体代码如下
package com.product;

import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.UUID;

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

import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;


import com.util.DividePage;
import com.util.UUIDTools;

public class ProductAction extends HttpServlet {

private ProductService service;
/**
* Constructor of the object.
*/
public ProductAction() {
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 {

this.doPost(request, response);
}

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

response.setContentType("text/html;charset=utf-8");
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
PrintWriter out = response.getWriter();

String action_flag = request.getParameter("action_flag");
if (action_flag.equals("add")) {
addProduct(request,response);
}else if (action_flag.equals("search")) {
listProduct(request,response);
}else if (action_flag.equals("del")) {
delProduct(request,response);
}else if (action_flag.equals("view")) {
viewProduct(request,response);
}


out.flush();
out.close();
}

private void viewProduct(HttpServletRequest request,
HttpServletResponse response) {
// TODO Auto-generated method stub
String proid = request.getParameter("proid");
Map<String, Object> map = service.viewProduct(proid);
request.setAttribute("productMap", map);
try {
request.getRequestDispatcher("/viewProduct.jsp").forward(request, response);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}

/**批量删除产品
* @param request
* @param response
*/
private void delProduct(HttpServletRequest request,
HttpServletResponse response) {
// TODO Auto-generated method stub

System.out.println("进入del");
//获得复选框的值
String[] ids = request.getParameterValues("ids");
for (int i = 0; i < ids.length; i++) {
System.out.println("ids["+i+"]="+ids[i]);
}
boolean flag = service.delProduct(ids);
System.out.println("删除flag:"+flag);
if (flag) {
try {
request.getRequestDispatcher("/main.jsp").forward(request, response);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

private void listProduct(HttpServletRequest request,
HttpServletResponse response) {
// TODO Auto-generated method stub

String productName = request.getParameter("proname");
String pageNum = request.getParameter("pageNum");
System.out.println("参数 pageNum :"+pageNum);
if (productName == null) {
productName = "";
}



int totalRecord = service.getItemCount(productName); //获取总的记录数
int currentPage = 1;
DividePage dividePage = new DividePage(5, totalRecord);//默认第一页开始
if (pageNum != null) {


currentPage = Integer.parseInt(pageNum);

dividePage.setCurrentPage(currentPage);
}

//记录从第几行开始
int start = dividePage.fromIndex();
//显示几条记录
int end = dividePage.toIndex();

System.out.println("currentPageNum :"+ dividePage.getCurrentPage() +", start = "+start +", end = "+end);

List<Map<String, Object>> list = null;
try {
list = service.listProduct(productName , start , end);
request.setAttribute("listProduct", list);
request.setAttribute("dividePage", dividePage);
request.setAttribute("productName",productName );
request.getRequestDispatcher("/main.jsp").forward(request, response);
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}

}

private void addProduct(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException{
//表单含有文件要提交
String path = request.getContextPath();
DiskFileItemFactory diskFileItemFactory = new DiskFileItemFactory();
ServletFileUpload servletFileUpload = new ServletFileUpload(diskFileItemFactory);
servletFileUpload.setFileSizeMax(3*1024*1024);//单个文件大小限制3M
servletFileUpload.setSizeMax(6*1024*1024);//上传文件总大小
List<FileItem> list = null;
List<Object> params = new ArrayList<Object>();
params.add(UUIDTools.getUUID()); // 参数传 product表的主键
try {
//解析request的请求
list = servletFileUpload.parseRequest(request);
//取出所有表单的值,判断非文本字段和文本字段
for(FileItem fileItem : list){
if (fileItem.isFormField()) {//是文本字段
String fileItemName = fileItem.getFieldName(); //获取 <input>控件的 名称
String fileItemValue = fileItem.getString("utf-8");//获取<input>控件的值
if (fileItemName.equals("proname")) {
params.add(fileItemValue); //参数传入 proname
}else if (fileItemName.equals("proprice")) {
params.add(fileItemValue);//参数传入 proprice
}else if (fileItemName.equals("proaddress")) {
params.add(fileItemValue);////参数传入 proaddress
}
}else{ //非文本字段

String imageName = fileItem.getName(); //获取文件名称
params.add(imageName);//参数传入 proimage
//String path = request.getRealPath("/upload");
String upload_dir = ((GenericServlet) request).getServletContext().getRealPath("/upload");//获取服务器端 /upload 路径
File uploadFile = new File(upload_dir+"/"+imageName);
System.out.println("---upload_dir--->>"+uploadFile);
fileItem.write(uploadFile);
}
}

// 把产品加入数据库
boolean flag = service.addProduct(params);
if (flag) {

response.sendRedirect(path+"/main.jsp");
}


} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}



}

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

}




求各位大神帮忙看看,小女子在此谢过。


ranhoudaima
...全文

相关推荐

2026安卓开发从零实战指南:环境搭建、核心基础与避坑干货(适配新版Android_Studio).pdf

2026安卓开发从零实战指南:环境搭建、核心基础与避坑干货(适配新版Android_Studio).pdf

彼岸交流群

如何实现科研成果转化率的有效提升与技术市场精准对接?.docx

如何实现科研成果转化率的有效提升与技术市场精准对接?

BIZKEEN

基于PID控制的ABS汽车防抱死制动系统、车轮滑移率+最优滑移率Carsim和Simulink联合仿真(带参考文献)

内容概要:本文档系统研究了基于PID控制的ABS汽车防抱死制动系统,聚焦于车轮滑移率与最优滑移率的动态控制问题,采用Carsim与Simulink联合仿真平台构建高精度车辆动力学模型与控制系统。研究详细阐述了ABS的工作机理,通过设计PID控制器实时调节制动压力,确保车轮滑移率稳定在最优区间,从而最大化轮胎与路面间的摩擦力,提升制动效能与行车安全性。文档涵盖了完整的建模流程、控制策略设计、仿真验证方法及参数整定过程,并提供了详实的参考文献支持,增强了研究的可复现性与工程应用价值。; 适合人群:具备车辆工程、自动化或控制理论等相关专业背景,熟悉MATLAB/Simulink与Carsim仿真环境的研究生、科研人员及汽车行业技术研发工程师。; 使用场景及目标:①用于ABS控制算法的教学讲解与科研实验;②支撑车辆制动性能优化、主动安全系统开发等实际工程应用;③为相关学术论文撰写、课题复现与技术创新提供理论依据与技术参考。; 阅读建议:建议读者结合所提供的仿真模型与参考文献,逐步运行并调试代码,重点关注滑移率计算逻辑、PID参数整定方法及联合仿真的数据交互机制,同时可尝试引入模糊控制、自适应控制等先进算法进行对比分析,以深入掌握ABS系统的控制精髓与优化路径。

荔枝科研社

高校如何利用技术转移数据分析优化成果转化路径?.docx

科易网基于40亿+科创知识图谱数据库,深度探索AI技术在技术转移、成果转化、技术经纪、知识产权、产业创新、科技招商等垂直领域的多样化应用场景,研究科技创新领域的AI+数智化解决方案,推动科技创新与产业创新智能化发展。

BIZKEEN

MATLAB采用改进的PSO实现AUV三维路径规划,配备自适应惯性权重、距离演化因子和跳出机制。.zip

MATLAB采用改进的PSO实现AUV三维路径规划,配备自适应惯性权重、距离演化因子和跳出机制。.zip

海神之光
评论 2
收藏 已收藏
分享
返回顶部
qq_35424597
Web 开发 81,108 成员 341,721 内容