


I have implemented the function of uploading Struts2 files and adding a progress bar, but why can't I get the return value of Struts2? Guys, please help me check_html/css_WEB-ITnose
This is the interface before uploading:
This is the interface when the upload is completed:
I just don’t know why I can’t get the interface
This is jsp Code
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/ struts-tags" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme() "://" request.getServerName() ":" request .getServerPort() path "/";
%>
<script> <br> var id=0; <br> var i = 0; var i = 0; function addressAction(){ <br> $.post( <br> './upload/pro gress.action', <br> function(data ; { <br> SetProgress(data.state.rate); In("slow");// Loading completion prompt <br> window.clearInterval(id); <br> var num=data.state.rate/10; <br> through "); <br> /gray.gif' />"); <br> <br> var progress_id = "loading"; <br> function SetProgress (progress) { <br> if (progress) { <br> $("#" progress_id " > div").css("width", String(progress) "%"); //Control #loading div width <br> $("#" progress_id " > div").html(String(progress) "%"); //Display percentage <br> } <br> } <br> <br> function submitForm(){ <br> if($("#f1").val()==""){ <br> alert('上传文件为空!!!'); <br> return ; <br> } <br> id=window.setInterval(addressAction,10); <br> $("form:first").submit();/*提交第一个表单*/ <br> } <br> </script>
enctype="multipart/form-data" target="hidden_frame">
File:
上传进度条的action
public class FileProgressAction extends ActionSupport {
private State state;
public State getState() {
return state;
}
public void setState(State state) {
this.state = state;
}
@Override
public String execute() throws Exception {
HttpSession session = ServletActionContext.getRequest().getSession();
this.state = (State) session.getAttribute("state");
if(state==null){
System.out.println("action is null");
state = new State();
state.setCurrentItem(0);
}else{
Double a=Double.parseDouble(state.getReadedBytes() "");
Double b=Double.parseDouble(state.getTotalBytes() "");
double result=a/b*100;
state.setRate((int)result);
}
return SUCCESS;
}
}
上传完成的action 返回值就在这里
public class FileProgressUploadAction extends ActionSupport{
private File file;
private String fileFileName;
private String fileContentType;
private String flag="===============";
public String getFlag() {
return flag;
}
public void setFlag(String flag) {
this.flag = flag;
}
public File getFile() {
return file;
}
public void setFile(File file) {
this.file = file;
}
public String getFileFileName() {
return fileFileName;
}
public void setFileFileName(String fileFileName) {
this.fileFileName = fileFileName;
}
public String getFileContentType() {
return fileContentType;
}
public void setFileContentType(String fileContentType) {
this.fileContentType = fileContentType;
}
@Override
public String execute(){
try {
System.out.println("file:" file);
InputStream is=new FileInputStream(file);
String root=ServletActionContext.getRequest().getRealPath("/upload");
System.out.println("root:" root);
System.out.println("name:" this.fileFileName);
System.out.println("type:" this.fileContentType);
File destFile=new File(root,this.fileFileName);
OutputStream os=new FileOutputStream(destFile);
byte [] b=new byte[1024*1024*10];
int length=0;
while(true){
length=is.read(b);
if(length<0)
break;
os.write(b,0,length);
}
setFlag("SUCCESS");
is.close();
os.close();
}catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("=====================");
return SUCCESS;
}
}
The post is quite long. I hope some kindhearted people can help me take a look. I’ve been thinking for a long time and haven’t found the reason.
Reply to the discussion (solution)
This is the struts.xml configuration file
< ;!-- Respecify the request encapsulation class -->
scope="default" optional="true" />

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











1. Introduction The Struts2 vulnerability is a classic series of vulnerabilities. The root cause is that Struts2 introduces OGNL expressions to make the framework flexible and dynamic. With the patching of the overall framework improved, it will now be much more difficult to discover new Struts2 vulnerabilities than before. Judging from the actual situation, most users have already repaired historical high-risk vulnerabilities. Currently, when doing penetration testing, Struts2 vulnerabilities are mainly left to chance, or it will be more effective to attack unpatched systems after being exposed to the intranet. Online analysis articles mainly analyze these Struts2 vulnerabilities from the perspective of attack and exploitation. As the new H3C offense and defense team, part of our job is to maintain the rule base of ips products. Today we will review this system.

How to implement file upload and processing in FastAPI FastAPI is a modern, high-performance web framework that is easy to use and powerful. It provides native support for file upload and processing. In this article, we will learn how to implement file upload and processing functions in the FastAPI framework, and provide code examples to illustrate specific implementation steps. First, we need to import the required libraries and modules: fromfastapiimportFastAPI,UploadF

How to solve the slow upload speed of Win10 computer? When we use the computer, we may feel that the file upload speed of our computer is very slow. So what is the situation? In fact, this is because the default upload speed of the computer is 20%, so the upload speed is very slow. Many friends do not know how to operate in detail. The editor has compiled the steps to format the C drive in Win11 below. If you are interested, follow Let’s take a look below! Solution to the slow upload speed of Win10 1. Press win+R to call up run, enter gpedit.msc, and press Enter. 2. Select the management template, click Network--Qos Packet Scheduler, and double-click Limit to reserve bandwidth. 3. Select Enabled, which will bring

With the advent of the digital age, music platforms have become one of the main ways for people to obtain music. However, sometimes when we listen to songs, we find that there are no lyrics, which is very disturbing. Many people hope that lyrics can be displayed when listening to songs to better understand the content and emotions of the songs. QQ Music, as one of the largest music platforms in China, also provides users with the function of uploading lyrics, so that users can better enjoy music and feel the connotation of the songs. The following will introduce how to upload lyrics on QQ Music. first

In website development, progress bars are an important part of the website. The progress bar shows the progress of the process. With the help of it, users can see the status of the work being done on the website, including load times, file uploads, file downloads, and other similar tasks. By default, it is gray. However, to make progress bars stand out and be visually appealing, you can use HTML and CSS to change their color. What is a progress bar? A progress bar is used to show the progress of a task. It is a graphical user interface element. It basically consists of a horizontal bar that gradually fills in as the task progresses, accompanied by a percentage value or other completion indicator. Progress bars are used in web applications to provide users with information about completing a process such as file upload, file download, or software installation.

1. Open Kugou Music and click on your profile picture. 2. Click the settings icon in the upper right corner. 3. Click [Upload Music Works]. 4. Click [Upload Works]. 5. Select the song and click [Next]. 6. Finally, click [Upload].

The principle of the Struts2 framework: 1. The interceptor parses the request path; 2. Finds the complete class name of the Action; 3. Creates the Action object; 4. Execute the Action method; 5. Returns the result; 6. View parsing. Its principle is based on the interceptor mechanism, which completely separates the business logic controller from the Servlet API, improving the reusability and maintainability of the code. By using the reflection mechanism, the Struts2 framework can flexibly create and manage Action objects to process requests and responses.

How does JavaScript implement the page loading progress bar function? In modern Internet applications, page loading speed is one of the key factors of user experience. To show users the loading process, many websites and applications use loading progress bars. JavaScript provides a simple and effective way to implement the page loading progress bar function. The specific implementation process is as follows: Create an HTML structure. First, create an HTML structure of a progress bar at a suitable location on the page. It is common to place the progress bar in
