Hello. This is a Struts 2 example to show the use of custom result type to download file. I have in jsp : - 1 password textfield - 1 submit button If I push submit button without insert a password I correctly obtain a field error "Field required!". Then If I set "XYZ" password (correct password), I correctly download "downloadfile.txt" but field error remain. Why? Thanks DownloadAction.java package com.example.common.action; import java.io.File; import java.io.FileInputStream; import java.io.InputStream; import com.opensymphony.xwork2.ActionSupport; public class DownloadAction extends ActionSupport{ private InputStream fileInputStream; private String password; public InputStream getFileInputStream() { return fileInputStream; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public void validate() { if ( (password==null) || (password.trim().equals("")) ) { addFieldError("password", "Field required!"); } if (!password.equals("XYZ") { addFieldError("password", "Wrong password!"); } } public String execute() throws Exception { fileInputStream = new FileInputStream(new File ("C:\\downloadfile.txt")); return SUCCESS; } } downloadPage.jsp <%@ taglib prefix="s" uri="/struts-tags" %>

Struts 2 download file example

struts.xml pages/downloadPage.jsp application/octet-stream fileInputStream attachment;filename="fileABC.txt" 1024 --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@struts.apache.org For additional commands, e-mail: user-help@struts.apache.org