在学习Struts2文件上传功能开发时,遇见一个问题,请高手进来帮我解决一下,谢谢啦!!!

爱吃猫的萌鱼 2010-10-24 10:14:19
我用的是Myeclipse6.5版本学习的,运行后提示了一个错误,找了半天也不知道错在哪儿了,错误代码是:


HTTP Status 500 -
type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception org.apache.jasper.JasperException: The Struts dispatcher cannot be found. This is usually caused by using Struts tags without the associated filter. Struts tags are only usable when the request has passed through its servlet filter, which initializes the Struts dispatcher needed for this tag. - [unknown location] org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:541) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:435) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266) javax.servlet.http.HttpServlet.service(HttpServlet.java:803)


root cause The Struts dispatcher cannot be found. This is usually caused by using Struts tags without the associated filter. Struts tags are only usable when the request has passed through its servlet filter, which initializes the Struts dispatcher needed for this tag. - [unknown location] org.apache.struts2.views.jsp.TagUtils.getStack(TagUtils.java:60) org.apache.struts2.views.jsp.StrutsBodyTagSupport.getStack(StrutsBodyTagSupport.java:44) org.apache.struts2.views.jsp.ComponentTagSupport.doStartTag(ComponentTagSupport.java:48) org.apache.jsp.jsp.upload_jsp._jspx_meth_s_005fform_005f0(upload_jsp.java:101) org.apache.jsp.jsp.upload_jsp._jspService(upload_jsp.java:70) org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) javax.servlet.http.HttpServlet.service(HttpServlet.java:803) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266) javax.servlet.http.HttpServlet.service(HttpServlet.java:803)


note The full stack trace of the root cause is available in the Apache Tomcat/6.0.13 logs.

Apache Tomcat/6.0.13

哎,根据错误找了半天还是找不出来,现在贴出源代码:

﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡


struts2的配置文件struts.xml:



<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
" http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constant name="struts.i18n.encoding" value="gb2312"></constant>
<constant name="struts.multipart.saveDir" value="c:\"></constant>
<package name="struts2_chapter4" namespace="/" extends="struts-default">
<global-results>
<result name="global">/jsp/upload.jsp</result>
</global-results>
<action name="upload" class="action.UploadAction">
<result name="input">/jsp/upload.jsp</result>
<result name="success">/jsp/result.jsp</result>
</action>
<action name="index">
<result>/jsp/upload.jsp</result>
</action>

</package>
</struts>



﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡

upload.jsp文件的源文件:

<%@taglib prefix="s" uri="/struts-tags"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=gb2312">
<title>上传文件</title>
</head>
<body>
<s:form action="upload" method="post" enctype="multipart/form-data">
<tr>
<td>上传文件:<s:file name="file"></s:file></td>
</tr>
<tr>
<td>再次上传文件:<s:file name="file"></s:file></td>
</tr>
<tr>
<td align="left"><s:submit name="submit" value="提交"></s:submit></td>
</tr>
</s:form>
</body>
</html>

﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡

result.jsp的源文件:

<%@taglib prefix="s" uri="/struts-tags"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=gb2312">
<title>上传结果</title>
</head>
<body>
上传文件:
<s:property value="fileFileName"/>
</body>
</html>

﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡


uploadAction.java的源文件:

package action;

import java.util.List;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class UploadAction extends ActionSupport{
private final static String UPLOADDIR="/upload";
private List<File> file;
private List<String> fileFileName;
private List<String> fileContentType;

public List<File> getFile(){
return file;
}
public void setFile(List<File> file){
this.file=file;
}
public List<String> getFileFileName(){
return fileFileName;
}
public void setFileFileName(List<String> fileFileName){
this.fileFileName=fileFileName;
}
public List<String> getFileContentType(){
return fileContentType;
}
public void setFileContentType(List<String> fileContentType){
this.fileContentType=fileContentType;
}
public String execute() throws Exception{
for(int i=0;i<file.size();i++){
upLoadFile(i);
}
return "success";
}
private void upLoadFile(int i)throws FileNotFoundException,IOException{
try{
InputStream in=new FileInputStream(file.get(i));
String dir=ServletActionContext.getRequest().getRealPath(UPLOADDIR);
File uploadFile=new File(dir,this.getFileFileName().get(i));
OutputStream out=new FileOutputStream(uploadFile);
byte[] buffer=new byte[1024*1024];
int length;
while((length=in.read(buffer))>0){
out.write(buffer,0,length);
}
in.close();
out.close();
}catch(FileNotFoundException ex){
ex.printStackTrace();
}catch(IOException ex){
ex.printStackTrace();
}
}
}
﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡
好了,源代码全贴出来了,如果需要源文件打包我可以站内发给你,虽然只是萍水相逢,还是感谢你的帮助!也虽然无以为报,感激之情无以言表!谢谢啦!我的qq是996475895,谢谢啦!
另外这是我在问问上的问题,竟然没人回答!http://wenwen.soso.com/z/q230068970.htm,有时间回答一下,有分数哦!
...全文
134 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
爱吃猫的萌鱼 2010-10-24
  • 打赏
  • 举报
回复
嘿嘿,谢谢 啊!真的,太感谢你了!现在没有报错了!就是出现了一点小问题,我想自己先找找!相信你是这方面的高手!能加你QQ吗?我想。。。嘿嘿,我都是自学Struts2,没有名师指导出错了还真是措手不及。。。以后有什么不懂多向你指教,虽然没有什么物质上的奖励,虽然也是只有感激之情,可是,对于我而言真是莫大的帮助,谢谢啦!qq:996475895!谢谢啦!真的,发自内心的!愿你好人有好报!
magicluo 2010-10-24
  • 打赏
  • 举报
回复
把这个代码加入到你的web.xml中

<!-- 配置struts2的核心过滤器 -->
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.FilterDispatcher
</filter-class>
</filter>

<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

然后重启你的web服务器 就应该没打问题了

最核心的地方你没配
爱吃猫的萌鱼 2010-10-24
  • 打赏
  • 举报
回复
首先非常感谢你的建议!
你这么一说我才发现我没有配置web.xml
我是自己自学struts2,所以这些配置还不是很熟悉,我打开我的web.xml,发现是这样的
﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡
<?xml version="1.0" encoding="UTF-8" ?>
- <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
- <welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>

﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡﹡
能教教我怎么配置吗?谢谢啦!不胜感激,真的,发自内心的感谢您!
magicluo 2010-10-24
  • 打赏
  • 举报
回复
我看你的问题出在 web.xml中
错误提示说的比较明白了,这通常是由于不经由Filter访问包含struts标签的jsp页面导致的


把web.xml文件中关于struts2 的过滤器改为 /* 看看

<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
【分布式能源选址与定容】光伏、储能双层优化配置接入配电网研究(Matlab代码实现)内容概要:本文围绕“分布式能源选址与定容”展开,重点研究光伏与储能系统在配电网中的双层优化配置问题,采用Matlab进行代码实现与仿真分析。通过建立数学模型,结合智能优化算法(如遗传算法、ADMM算法等),对光伏和储能的安装位置、容量配置进行协同优化,旨在提升配电网运行效率、降低网损、改善电压稳定性,并促进可再生能源的高效接入与利用。文中还涉及多个相关研究方向的案例与代码资源,涵盖微电网调度、需求响应、电力系统仿真等内容,形成较为完整的科研技术支撑体系。; 适合人群:具备电力系统基础知识,熟悉Matlab编程,从事新能源接入、智能电网优化等相关领域的研究生、科研人员及工程技术人员。; 使用场景及目标:①开展分布式光伏与储能系统的规划配置研究;②学习双层优化模型在配电网中的建模与求解方法;③掌握遗传算法、ADMM等智能算法在电力系统优化中的实际应用;④复现IEEE标准节点系统下的仿真案例,支撑论文写作与项目开发。; 阅读建议:建议结合提供的Matlab代码与网盘资料,边学习理论模型边动手实践仿真,重点关注目标函数构建、约束条件设置及算法收敛性分析,同可参考文中提及的IEEE33、IEEE118等标准测试系统进行验证与拓展研究。

81,116

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧