You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Wangenheim, Marc" <MW...@GAIC.COM> on 2002/09/17 16:10:18 UTC

Multipartform and validate(). Is this a bug ?

I'm having some problems with the validate() method on a jsp that
contains a enctype="multipart/form-data" form to support file upload. I
am using struts release 1.0.2. I am using session based security as
well. The jsp contains multiple fields and all but the file upload and
file description field are validated through the validate() method. The
fields that have to do with the file upload are not required and
therefore are not being validated. If a user tries to submit the form
and omits one/all of the required fields the user gets an error message
generated by the validate() method. My problem is that when the session
times out and the user has not populated all required fields struts
throws a ServletException in
org.apache.struts.upload.MultipartIterator.parseRequest. It's almost as
if struts is trying to re-display data on the file upload fields even
though they are not being validated. I attached the jsp and the stack
trace at the end of this email. I also attached a couple of screenshots.
To overcome this issue I ended up checking the validity of the session
within the validate() method and redirect to the login page if the
session had timed out. But I just don't understand why I have to handle
it this way. Any help greatly appreciated.

-Marc Wangenheim

My fix:
public ActionErrors validate(ActionMapping aMapping, HttpServletRequest
aRequest) {
  if (aRequest.getSession().getAttribute("edHID")==null) {
    ActionErrors err =  new ActionErrors();
    return err;
  }
  return mTableImpl.validate();
}  // validate()


The JSP:
<%@ page errorPage="SHSMI_Error.jsp" %>
<%@ page import="com.gaic.bsg.app.shsmi.*" %>
<%@ page import="com.gaic.bsg.lib.security.*" %>
<%@ page import="com.gaic.bsg.lib.utils.*" %>
<%@ page import="java.net.*" %>
<%@ page import="java.util.*" %>
<%@ page import="com.gaic.bsg.tables.*" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<jsp:include page="LoginCheck.jsp"/>
<% Table_SHSMI shsmi=(Table_SHSMI) session.getAttribute ("Table_SHSMI");
    if (StringEx.isEmpty(shsmi.getLast_Saved())) {
      if (!Security.hasRole(session,Security.ROLE_CREATE))
        throw new Exception("You are not authorized to create
documents");
      }
    else {
      if (!Security.hasRole(session,Security.ROLE_EDIT))
        throw new Exception("You are not authorized to edit documents");
      } %>
<% SHSMI_Display webForm=new
SHSMI_Display(Table_SHSMI.NAME,pageContext); %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Expires" CONTENT="-1">
<title>SHS Market Intelligence</title>
<html:base/>
</head>
<body bgcolor="#FFFFFF" text="#000000" id="all" leftmargin="10"
topmargin="10" marginwidth="10" marginheight="10" link="#CC0000"
vlink="#003399" alink="#999999">
<script type='text/javascript'>
// cancelConfirm: Confirm that the user really intends to cancel the
edit
function cancelConfirm() {
answer = confirm("Are you sure that you want to exit without saving?");
if (answer) window.location="SHSMI_Main.jsp"
}
// save: Submits the form back to struts
function save(){
var aform = document.forms[0];
if (aform.attachment.value>"") {
  alert("You must click the 'Add Attachment' button to attach the file
before saving the document");
  aform.attachment.focus();
}
else {
aform.action="SHSMI_Save.do";
aform.submit();
}
}
// attachFile: Attaches a file to the document
function attachFile(){
var aform = document.forms[0];
if (aform.attachment.value>"") {
aform.action="SHSMI_Save_Attachment.do";
aform.Attach.disabled=true
aform.Attach.value="Please Wait"
aform.submit();
}
else
  alert("Specify a filename before clicking the 'Add Attachment'
button.");
}
// removeConfirm: Confirm that the user really intends to cancel the
edit
function removeConfirm(url) {
answer = confirm("Are you sure that you want to remove this
attachment?");
if (answer) window.location=url
}
</script>
<script type='text/javascript' src='menu_com.js'></script>
<%= webForm.createEditJSMenu() %>
<table bgcolor="#FFFFFF" border="0" cellpadding="0" cellspacing="0"
width="730" align="left">

<tr><td><table bgcolor="#000066" cellpadding="0" width="100%"
border="0"><tr><td height="17"></td></tr></table></td></tr>
<tr><td colspan="8" valign="bottom"><img  src="images/SHSheader.gif"
name="header" border="1"></td></tr>
<tr>
    <td bgcolor="#FFFFFF" colspan="9"><b><font face="verdana, arial,
helvetica" size="1">&nbsp;</font></b></td>
  </tr>
    <tr>
     <td>
      <table cellpadding="0" cellspacing="1" border="0"  width="750"
bgcolor="#FFFFFF">
      <tr><td>
<html:errors/>
<html:form action="SHSMI_Save.do" enctype="multipart/form-data">
<table border="0" width="100%" cellspacing="0" cellpadding="0">
<tr><td width="17%">Author:</td><td width="83%"><b><bean:write
name="Table_SHSMI" property="authorName"/></b></td></tr>
<tr><td width="17%">Effective Date:</td><td width="83%"><html:text
property="effective_Date" size="10"/></td></tr>
<tr><td width="17%">Company Name:</td><td width="83%"><html:text
property="company_Name" size="30"/></td></tr>
<tr><td width="17%">Categories:</td><td width="83%">
  <html:select property="categories" size="1">
  <html:options collection="Categories_Collection" property="value"
labelProperty="label"/>
  </html:select></td></tr></table>
  <br>
   Competitor Information: <br>
  <html:textarea cols="91" rows="12" property="competitor_Information"
/> <br>
  <%= Attachments.getAttachmentEditDisplay(SHSMI_Const.APP_NAME,
                                           Table_SHSMI.NAME,
                                           shsmi.getId(),
 
StringEx.isEmpty(shsmi.getLast_Saved()),
 
shsmi.getDeletedAttachments(),
                                           webForm.getDatabase(),
                                           webForm.getStatement(),
                                           session) %>
<b><font color="red"><h3><bean:write name="Table_SHSMI"
property="attachmentError"/></h3></font></b>
<table border="0" width="100%" cellspacing="0" cellpadding="0">
<tr><td width="20%">Filename:</td><td width="80%"> <html:file
property="attachment" size="56"/>&nbsp;&nbsp;
<input type="button" name="Attach" value="Add Attachment"
onClick="attachFile()"></td></tr>
<tr><td valign="top" width="20%">Description:</td><td
width="80%"><html:textarea cols="72" rows="4"
property="attachmentDesc"/></b></td></tr>
</table>
</html:form>
      </td></tr>
      </table>
    </td>
  </tr>
</table>
<% webForm.terminate(); %>
</body>
</html>

The stack trace:
javax.servlet.ServletException: MultipartIterator: no multipart request
data sent
 	at
org.apache.struts.upload.MultipartIterator.parseRequest(MultipartIterato
r.java:342)
 	at
org.apache.struts.upload.MultipartIterator.<init>(MultipartIterator.java
:152)
 	at
org.apache.struts.upload.DiskMultipartRequestHandler.handleRequest(DiskM
ultipartRequestHandler.java:65)
 	at
org.apache.struts.util.RequestUtils.populate(RequestUtils.java:735)
 	at
org.apache.struts.action.ActionServlet.processPopulate(ActionServlet.jav
a:2061)
 	at
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1564)
 	at
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:510)
 	at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
 	at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
 	at
org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatc
her.java:683)
 	at
org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDisp
atcher.java:431)
 	at
org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispat
cher.java:355)
 	at
org.apache.jasper.runtime.PageContextImpl.forward(PageContextImpl.java:4
14)
 	at
org.apache.jsp.LoginCheck$jsp._jspService(LoginCheck$jsp.java:74)
 	at
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:107)
 	at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
 	at
org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServle
t.java:202)
 	at
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:382)
 	at
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:474)
 	at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
 	at
org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatc
her.java:683)
 	at
org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDisp
atcher.java:574)
 	at
org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispat
cher.java:497)
 	at
org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.ja
va:819)
 	at
org.apache.jsp.SHSMI_0005fForm$jsp._jspService(SHSMI_0005fForm$jsp.java:
98)
 	at
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:107)
 	at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
 	at
org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServle
t.java:202)
 	at
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:382)
 	at
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:474)
 	at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
 	at
org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatc
her.java:683)
 	at
org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDisp
atcher.java:431)
 	at
org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispat
cher.java:355)
 	at
org.apache.struts.action.ActionServlet.processValidate(ActionServlet.jav
a:2149)
 	at
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1565)
 	at
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:510)
 	at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
 	at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
 	at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Applica
tionFilterChain.java:247)
 	at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilt
erChain.java:193)
 	at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValv
e.java:243)
 	at
org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.ja
va:566)
 	at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:4
72)
 	at
org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
 	at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValv
e.java:190)
 	at
org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.ja
va:566)
 	at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:4
72)
 	at
org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
 	at
org.apache.catalina.core.StandardContext.invoke(StandardContext.java:234
3)
 	at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java
:180)
 	at
org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.ja
va:566)
 	at
org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherVa
lve.java:170)
 	at
org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.ja
va:564) 
	at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java
:170) 
	at
org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.ja
va:564) 	
	at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:4
72) 	
	at
org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
 	at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.
java:174) 
	at
org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.ja
va:566) 
	at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:4
72) 
	at
org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
 	at
org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.j
ava:1012)
 	at
org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:
1107) 	at java.lang.Thread.run(Thread.java:484)

Screenshots:
 <<JSP.jpg>>  <<JSP-Errors.jpg>>  <<Login.jpg>>