使用Eclipse 3.1 WST编写Struts文件上传

Eclipse JEE版文件名解析与JVM启动配置指南 Eclipse IDE 是面向Java开发者的主流集成开发环境,其发行版命名体系隐含平台、功能、版本、架构等关键信息。理解如 'eclipse-jee-2023-09-R-win32-x86-64' 这类文件名,本质是掌握Jakarta EE开发环境的兼容性契约;而JVM启动参数(如 -Xmx、-XX:+UseParallelGC、-vm)则直接决定IDE在Windows下的稳定性与性能表现。这些配置不仅影响Tomcat集成、Maven构建和中文支持,更关系到企业级Web项目能否顺利启动与调试。本文聚焦Ec 阅读详情

可以在eclipse.org网站上下载WST with Eclipse3.1文件,该文件包括Eclipse3.1和WST以及它所需要的所有插件,基本上不用装其他插件了。

解包下载的文件后,建立新项目:Dynamic Web Project,这是需要配置调试用的Web服务器。我使用Tomcat 5.5,填写Tomcat 5.5的安装目录。

将Struts所需要的lib和Tld文件拷贝到WEB-INF目录

在WEB-INF/config目录里编写struts-config.xml如下

<?xml version="1.0" encoding="ISO-8859-1" ?>

<!DOCTYPE struts-config PUBLIC
          "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN"
          "http://jakarta.apache.org/struts/dtds/struts-config_1_2.dtd">

<!--
     This is the Struts configuration file of Colimas
  Created By: Zhao Lei
  Created Date:2005/06/14
  Last Modified By: Zhao Lei
  Last Modified Date:2005/07/25
-->


<struts-config>
<!-- ================================================ Form Bean Definitions -->

    <form-beans> 
       <!--30 Upload File formbean-->         
       <form-bean
   name="UploadForm"
   type="com.nova.colimas.web.form.UploadForm"/>  

    </form-beans>


<!-- ========================================= Global Exception Definitions -->

    <global-exceptions>
        <!-- sample exception handler
        <exception
            key="expired.password"
            type="app.ExpiredPasswordException"
            path="/changePassword.jsp"/>
        end sample -->
    </global-exceptions>


<!-- =========================================== Global Forward Definitions -->

    <global-forwards>
        <!-- Default forward to "Welcome" action -->
        <!-- Demonstrates using index.jsp to forward -->
        <forward
            name="index"
            path="/index.do"/>
    </global-forwards>


<!-- =========================================== Action Mapping Definitions -->

    <action-mappings>
            <!-- Default "Welcome" action -->
            <!-- Forwards to Welcome.jsp -->
        <action  path="/index"
            forward="/pages/index.jsp"/>  

  <!-- 45 File Load Action-->
    <action    path="/protect/FileLoadAction"
              type="com.nova.colimas.web.action.protect.FunctionImportAction"
              name="UploadForm"
              scope="request">
              <forward name="success" path="/index.do"/>
  </action>
            

        
    </action-mappings>


<!-- ============================================= Controller Configuration -->

    <controller
       processorClass="org.apache.struts.tiles.TilesRequestProcessor"/>


<!-- ======================================== Message Resources Definitions -->
    <message-resources parameter="resources.template" />
<!-- =============================================== Plug Ins Configuration -->

    <plug-in className="org.apache.struts.tiles.TilesPlugin" >

      <!-- Path to XML definition file -->
      <set-property property="definitions-config"
                       value="/WEB-INF/config/tiles-defs.xml" />
      <!-- Set Module-awareness to true -->
      <set-property property="moduleAware" value="true" />
    </plug-in>


  <!-- =================================================== Validator plugin -->

  <plug-in className="org.apache.struts.validator.ValidatorPlugIn">
    <set-property
        property="pathnames"
        value="/WEB-INF/config/validator-rules.xml,/WEB-INF/config/validation.xml"/>
  </plug-in>

</struts-config>

修改Web.xml将struts-config.xml填进去:

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
 <display-name>
 colimas</display-name>
  <display-name>Component Library Management System</display-name>

 <servlet>
    <!-- Standard Action Servlet Configuration (with debugging) -->
   <servlet-name>action</servlet-name>
   <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
   <init-param>
     <param-name>config</param-name>
     <param-value>/WEB-INF/config/struts-config.xml</param-value>
   </init-param>
   <init-param>
     <param-name>debug</param-name>
     <param-value>2</param-value>
   </init-param>
   <init-param>
     <param-name>detail</param-name>
     <param-value>2</param-value>
   </init-param>
   <load-on-startup>2</load-on-startup>
 </servlet>
 <servlet-mapping>
    <!-- Standard Action Servlet Mapping -->
   <servlet-name>action</servlet-name>
   <url-pattern>*.do</url-pattern>
 </servlet-mapping>
 <welcome-file-list>
  <welcome-file>welcome.jsp</welcome-file>
 </welcome-file-list>

 <jsp-config>
   <taglib>
     <taglib-uri>http://java.sun.com/jsp/jstl/core</taglib-uri>
     <taglib-location>/WEB-INF/tld/c.tld</taglib-location>
   </taglib>
   <taglib>
     <taglib-uri>http://java.sun.com/jsp/jstl/fmt</taglib-uri>
     <taglib-location>/WEB-INF/tld/fmt.tld</taglib-location>
   </taglib>
   <taglib>
     <taglib-uri>http://java.sun.com/jsp/jstl/sql</taglib-uri>
     <taglib-location>/WEB-INF/tld/sql.tld</taglib-location>
   </taglib>
   <taglib>
     <taglib-uri>http://java.sun.com/jsp/jstl/xml</taglib-uri>
     <taglib-location>/WEB-INF/tld/x.tld</taglib-location>
   </taglib>
   <taglib>
     <taglib-uri>http://java.sun.com/jsp/jstl/functions</taglib-uri>
     <taglib-location>/WEB-INF/tld/fn.tld</taglib-location>
   </taglib>
   <taglib>
     <taglib-uri>/tags/struts-bean</taglib-uri>
     <taglib-location>/WEB-INF/tld/struts-bean.tld</taglib-location>
   </taglib>
   <taglib>
     <taglib-uri>/tags/struts-html</taglib-uri>
     <taglib-location>/WEB-INF/tld/struts-html.tld</taglib-location>
   </taglib>
   <taglib>
     <taglib-uri>/tags/struts-logic</taglib-uri>
     <taglib-location>/WEB-INF/tld/struts-logic.tld</taglib-location>
   </taglib>
   <taglib>
     <taglib-uri>/tags/struts-tiles</taglib-uri>
     <taglib-location>/WEB-INF/tld/struts-tiles.tld</taglib-location>
   </taglib>
   <taglib>
     <taglib-uri>/tags/struts-nested</taglib-uri>
     <taglib-location>/WEB-INF/tld/struts-nested.tld</taglib-location>
   </taglib>
 </jsp-config>
 
</web-app>
编写welcome.jsp和/pages/index.jsp文件

<%@ taglib uri="/tags/struts-logic" prefix="logic" %>
<logic:redirect forward="index"/>
<%--
Redirect default requests to Welcome global ActionForward.
By using a redirect, the user-agent will change address to match the path of our Welcome ActionForward.

--%>

index.jsp

<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib uri="/tags/struts-logic" prefix="logic" %>

<html:html>
 <Title>Upload Files</Title>
 <body>
  <html:form action="/protect/FileLoadAction.do" enctype="multipart/form-data">
   <html:file property="theFile"/>
   <html:submit/>
  </html:form>
  <bean:write name="UploadForm" property="theText"/>
 </body>
</html:html>

注意红字属性必须填写,否则会出错。该<html:file>只能上传一个文件,如果要上传多个只能

<html:file property="theFile1"/>
<html:file property="theFile2"/>
<html:file property="theFile3"/>
不支持无定数文件上传。

编写Action和ActionForm

/*
 * Created on 2005/07/21
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package com.nova.colimas.web.action.protect;

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

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessages;
import org.apache.struts.upload.FormFile;

import com.nova.colimas.common.doc.*;
import com.nova.colimas.web.form.UploadForm;

/**
 * @author tyrone
 *
 */
public class FunctionImportAction extends Action {
 public ActionForward execute(ActionMapping mapping,
    ActionForm form,
    HttpServletRequest request,
    HttpServletResponse response)
 throws Exception{  
  /**
   * 1 File Upload the file
   * 2 get the value from WordProcess
   * 3 Analysis
   * 4 show to user
   */
  if (form instanceof UploadForm){
   String text=null;
   UploadForm theForm = (UploadForm ) form;
   FormFile file = theForm.getTheFile();//Ž擾
   if(file.getFileName().endsWith("doc")){
    //使用本站提供的Word和Excel分析类可以提取文本字符串,上传文件内容将显示在jsp网页上

     text=WordProcess.run(file.getInputStream());
   }else if(file.getFileName().endsWith("xls"))
     text=ExcelProcess.run(file.getInputStream());
    else
     text=TextProcess.run(file.getInputStream());
   theForm.setTheText(text);
   
  }
  return mapping.findForward("success");
 }
}

/*
 * Created on 2005/06/25
 * @Author Tyrone
 * Save the upload file info and stream
 * used by struts FormFile
 */
package com.nova.colimas.web.form;

import org.apache.struts.action.ActionForm;
import org.apache.struts.upload.*;
/**
 * @author tyrone
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class UploadForm extends ActionForm {

 private FormFile theFile;
 private String theText;

 
 /**
  * @return Returns the theFile.
  */
 public FormFile getTheFile() {
  return this.theFile;
 }
 /**
  * @param theFile The theFile to set.
  */
 public void setTheFile(FormFile property1) {
  this.theFile = property1;
 }
 public void Reset() {
  this.theFile=null;
  this.theText="";
  return;
 }
 /**
  * @return Returns the theText.
  */
 public String getTheText() {
  return theText;
 }
 /**
  * @param theText The theText to set.
  */
 public void setTheText(String property1) {
  this.theText = property1;
 }

}

调试welcome.jsp。eclipse会启动Tomcat,在Console里打印启动log,其中会出现:web.xml cannot be found

这个错误可以忽略,不会有问题。

选择文件,点击index.jsp的submit。程序会跳转到FunctionImportAction 。如果在FunctionImportAction 设断点,可以停到断点出。非常方便。


纯JavaEE图书管理系统:Struts2+JDBC+原生JSP实战 JavaEE是企业级Web开发的基础技术体系,其核心在于Servlet、JSP、JDBC与MVC分层架构的协同运作。本文围绕一个不依赖Spring Boot、MyBatis或Maven的原生JavaEE图书管理系统展开,深入解析Struts2拦截器链执行机制、JDBC手动事务控制原理及JSP与Servlet的请求流转逻辑。系统完整实现用户登录、图书增删改查、封面上传校验与角色权限拦截,技术价值在于回归JavaEE规范本质,帮助开发者建立对DAO层事务边界、Filter/Interceptor职责划分及Web 阅读详情

相关推荐

struts_框架文件上传文件-Eclipse

最近自学java中的框架-struts写了一些小例子,这都是很经典的程序,如果大家瞧得起要下载去看看,顺便给俺找找不足的地方。我的qq 821865130 email qingtian_hechen@163.com 希望大家能多多给我帮助。在此谢谢各位!!

Eclipse中struts的引入

Eclipse中struts的使用1.下载struts库 打开网址:http://struts.apache.org/ 点击download,点击下载:struts-2.3.31-all.zip (65MB)2.解压struts-2.3.31-all.zip ,进入目录apps,解压struts2-blank.war,进入WEB-INF/lib,复制所有jar包,保存一个自己喜欢的目录,比如:D:\

get and write 8249

eclipse下利用struts2实现文件的上传和下载

可以单文件或多文件上传和下载,如需要改变上传路径例如上传到本地磁盘(D:\)下只需稍加修改即可,再次非常感谢大虾李顺利。

Problems occurred when invoking code from plug-in: "org.eclipse.jface".

java.lang.NullPointerException at com.genuitec.eclipse.easie.core.AppServer.getServerLabel(Unknown Source) at com.genuitec.eclipse.ast.deploy.core.ui.dialog.DeploymentLabelProvider.getColumnText(Unkno...

weixin_34349320的博客 252

三菱FX3U PLC红绿灯ST编程实战:从基础逻辑到急停功能完整实现

本文以十字路口红绿灯控制为例,详细讲解了三菱FX3U PLC使用ST编程的完整实战过程。内容涵盖从基础时序逻辑、状态机设计,到急停功能、黄灯闪烁、昼夜模式切换等高级功能的实现,并提供了代码优化与调试技巧,帮助工程师掌握结构化文本在工业控制中的清晰、结构化应用。

weixin_29070861的博客 541

STM32CubeMX 6.4.0 + STM32F407ZGT6 实战:基于YT8512C PHY的lwIP以太网配置与调试

本文详细介绍了使用STM32CubeMX 6.4.0为STM32F407ZGT6微控制器配置YT8512C PHY芯片,并成功移植lwIP以太网协议栈的实战过程。文章从硬件差异分析入手,逐步讲解时钟配置、ETH外设设置、PHY寄存器适配以及lwIP协议栈剪裁等关键步骤,旨在帮助开发者解决非标准PHY芯片的联网难题,最终实现网络连通与Ping测试。

n8m7b6v5c4的博客 598

Eclipse快捷键的上下文感知原理与Java开发提效实战

Eclipse并非传统意义上的代码编辑器,而是一个具备上下文感知能力的Java集成开发环境(IDE)。其快捷键响应依赖于编辑器类型、焦点控件状态和选中内容的语义结构三层动态绑定机制,而非静态键位映射。理解这一原理,是突破‘快捷键失效’困境、实现跨平台(Mac/Windows)一致操作的基础。技术价值在于将重复性交互转化为条件反射式操作,显著降低认知负荷;典型应用场景涵盖Spring Boot多模块导航、微服务调试、Lambda重构及遗留系统迁移。本文聚焦Java开发者高频任务链——如Open Type(Ct

weixin_34128237的博客 302

实测338MB/s!FPGA与CYUSB3014的Slave FIFO模式实战避坑(附完整固件与源码)

本文详细介绍了FPGA与CYUSB3014在Slave FIFO模式下实现338MB/s高速数据传输的实战经验。通过优化硬件设计、固件配置和GPIF II接口设置,解决了USB3.0双向通信中的关键性能瓶颈,并提供了完整的固件与源码参考。

weixin_30570101的博客 459

Eclipse 如何修改 Web 项目的名称

Eclipse 切换到 Navigator 视图,能显现出项目下所有的文件便于修改。 1、修改该项目目录下:.project文件 <projectDescription><name>Struts2_0200_Namespace</name><comment></comment><projects></proje...

weixin_30375427的博客 146

【数据同化第一期】基本概念介绍

【数据同化第一期】基本概念介绍

WW、forever的博客 1916

R语言中的summarise函数和mutate函数用于计算分组占比。下面是关于这两个函数的详细介绍以及相应的源代码示例:

R语言中的summarise函数和mutate函数用于计算分组占比。

CodeByte的博客 1183

Run on Server报错:The server does not support version 3.0 of the J2EE Web module specification

今天用Eclipse开发Struts2的项目时,点击右键Run on Server时出现: The server does not support version 3.0 of the J2EE Web module specification   创建这个项目时用的Tomcat 6.0 ,JDK的版本为1.6,而Tomcat 6.0 能支持的Servlet的版本为2.5. 在网上找到一个

lw744355998的专栏 726

OTA 升级失败/回滚策略设计:打造安全可靠的双分区/断点续传/签名校验方案

双分区机制(A/B Partitioning)是OTA升级的“保险箱”。简单来说,设备存储分为两个分区:A分区(当前运行)和B分区(备用)。升级时,新固件写入B分区,A分区保持不变。如果升级成功,系统切换到B分区运行;如果失败,设备直接回滚到A分区,完全不受影响。这就像玩游戏存档:你打Boss前存了个档,万一挂了还能读档重来。双分区就是设备的“读档”机制,避免了变砖的尴尬。以Android设备为例,Google从Android 7.0开始强制引入A/B分区机制(Seamless Updates)。

大模型大数据攻城狮的专栏 1241

在eclipse中启动tomcat时,出现以下错误

在eclipse中启动tomcat时,出现以下错误。不要慌 [code="java"]Unable to load configuration. - bean - jar:file:/E:/Users/lvgl/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/Lyglxt/WEB-INF/lib/struts2-cor...

雨滴 320

【DaVinci Configurator专题】-6-将UDS&OBD诊断数据库文件CDD和PDX导入到CFG

CDD和ODX是两种诊断数据库文件。机器可读的诊断数据库其实就是将传统的Excel调查表等信息编辑成CDD或ODX文件。CDD是Vector私有的一种诊断数据库格式;ODX是国际标准的诊断数据交互格式。CANdelaStudio编辑CDD文件,以及也可以导出ODX文件;ODX Studio用于编辑ODX文件,诊断数据库的编辑其实就是诊断需求的定义。 下面以PDX为例,将其导入到DaVinci Configurator。 目录 1 打开DaVinci Configurator,导入PDX文件 2 解.

「汽车电子助手」的博客 6763

Claude Code、Codex、Gemini CLI、OpenCode 和 OpenClaw 配置管理太麻烦?试试这个统一管理工具

还在为 Claude Code、Codex、Gemini CLI 等 AI CLI 配置烦恼?🤯 这款桌面工具支持五大助手统一管理,一键切换 50+ 服务商,MCP 和 Skills 集中管理 🛠️,跨平台支持,让你的 AI 编程更高效 ⚡

XiaoqiangClub的博客 921

org

/m5(自己的类全注解+别人的类xml)/m5_web/.settings/org.eclipse.wst.common.project.facet.core.xml<?xmlversion="1.0"encoding="UTF-8"?> <faceted-project> <fixedfacet="wst.jsdt.web"/> <inst...

weixin_43292547的博客 132

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

(转)[Tomcat]eclipse中Tomcat导入项目并且修改了项目名字,项目后面的括号显示

号显示原来项目的名字,并且在访问的时候也只能用原来的项目名访问,怎么办呢?     遇到这个问题,我也是在CSDN博客中找答案的,但是根据答案去实践,发现并不全面,以下给出比较全面的解决办法,个人实践得出,可能环境不相同或者情况不一样稍有偏差,但不妨一试     1.打开你的项目目录,找到一个.project文件,打开后修改&lt;name&gt; test&lt;/name&gt;中的值,将test修改成你要修改的名字;     2.在项目目录下,打开.s

jameskaron的专栏 183

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

Struts 2 项目打包名称不是项目名称之“灵异事件 ”

Hello大家好,想必代码世界无bug不有,但是善于出现“灵异事件 ”,由于从svn上下载了一个新的项目,打算启动运行一下,emmm完事就悲剧了,发现host里面配置完事之后,去访问项目,结果报错了耶,之后就去各种找bug,结果问题关键所在,没错就是“灵异事件”,因为现在的这个项目的包的名字无论怎么删除,之后在重新打包,它还是那个名字,哇贼顽强有木有,直!接!上!图!表示问题,然后就去调查原因了呗

lvjingbin的博客 293

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

2006 Java技术的赢家和输家

Here are my winners and, yes, even losers for the most and least innovative and/or impacting Java technologies in 2006…Here are the winners:Java IDE Platform/general Java Framework* NetBeans IDE

纯月部落 4412

2007 Java技术的赢家和输家

Here are my winners and, yes, even losers for the most and least innovative and/or impacting Java technologies in 2006…Here are the winners:Java IDE Platform/general Java Framework* NetBeans IDE

首席技术执行官CTO(Chief Technology Officer)|技术总监--邓斌博客 1225
上一篇: [原创]组件库管理系统的构成(英文)
下一篇: Java实现MessageBox类
tyrone1979
博客等级 码龄25年 194粉丝 96原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值