Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Frameworks
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Other Application Frameworks
problem in uploading the file in springframework
amity raj
Greenhorn
Posts: 4
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I am enclosing the code here please suggest modifications if any
this is my form:
<%@ include file="/WEB-INF/jsp/include.jsp" %> <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Insert title here</title> </head> <body> <form:form action="updateConfig.html" method="POST" enctype="multipart/form-data"> <div align="center"> <fieldset> <legend ><font color="#666666">Config List</font></legend> <table border="0" width="729" id="table1" cellspacing="0"> <tr> <td width="393" colspan="3" ></td> <td width="332"></td> </tr> <tr> <td align="left" width="30%" class="list-header">Label</td> <td align="left" width="70%" class="list-header">Value</td> </tr> <c:forEach items="${configList}" var="l"> <tr> <td width="30%" align="left"><c :-o ut value="${l.label}" /></td> <td width="70%" align="left"><c:if test="${l.label=='filelocation'}"><input type="file" id="filename" name="filename" size="40" value="<c :-o ut value="${l.value}"/>"/></c:if><c:if test="${l.label!='filelocation'}"><input type="text" id="value" name="value" size="40" value="<c :-o ut value="${l.value}" />"/></c:if></td> </tr> </c:forEach> </table> </fieldset> </div> <div align="center"> <input type="submit" id="submit" value="Save Config" /> </div> </form:form> </body> </html>
this is my UpdateConfigController's code :
package com.igs.tup.config.controller; import java.io.File; import java.util.Iterator; import java.util.List; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.commons.fileupload.FileItem; import org.apache.commons.fileupload.FileItemFactory; import org.apache.commons.fileupload.FileUploadException; import org.apache.commons.fileupload.disk.DiskFileItemFactory; import org.apache.commons.fileupload.servlet.ServletFileUpload; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.mvc.Controller; import org.springframework.web.servlet.view.RedirectView; import com.igs.tup.config.pojos.Config; import com.igs.tup.config.services.ConfigServices; public class UpdateConfigController implements Controller{ protected ConfigServices service; protected List<Config> configList; public void setConfigService(ConfigServices value){ this.service=value; } public ModelAndView handleRequest(HttpServletRequest request,HttpServletResponse response) throws Exception { System.out.println("update Controllers Handle method called"); String ParameterNames="value"; String[] s=request.getParameterValues(ParameterNames); configList=service.getConfigList(); Config[] configArray=configList.toArray(new Config[0]); boolean isMultipart = ServletFileUpload.isMultipartContent(request); System.out.println(isMultipart); if (!isMultipart) { for(int i=0;i<=s.length-1;i++){ configArray[i].setValue(s[i]); } } else { FileItemFactory factory = new DiskFileItemFactory(); ServletFileUpload upload = new ServletFileUpload(factory); List items = null; try { items = upload.parseRequest(request); } catch (FileUploadException e) { e.printStackTrace(); } Iterator itr = items.iterator(); while (itr.hasNext()) { FileItem item = (FileItem) itr.next(); if (item.isFormField()){ for(int i=0;i<=s.length-1;i++){ configArray[i].setValue(s[i]); } else{ String itemName = item.getName(); File savedFile = new File(request.getSession().getServletContext().getRealPath("/")+itemName); item.write(savedFile); } }
[ December 17, 2008: Message edited by: amity raj ]
[ December 17, 2008: Message edited by: amity raj ]
amity raj
Greenhorn
Posts: 4
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I am unable to write the file. Please help me find out the mistakes in my code.I have added the bean MultipartResolver to my Spring-Config file.I have also added the jar files commons-fileUpload.jar to my lib folder.
amity raj
Greenhorn
Posts: 4
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
this is my Display Controller
public class DisplayConfigListController implements Controller { protected final Log logger = LogFactory.getLog(getClass()); protected ConfigServices service; public void setConfigService(ConfigServices value){ this.service=value; } public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception { // TODO Auto-generated method stub System.out.println("Display Controllers Handle method called"); List<Config> configList=service.getConfigList(); for(Config c : configList ){ c.toString(); System.out.println(c.toString()); } return new ModelAndView(".config-admin-display","configList",configList); } }
this is my spring-config
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans <a href="http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">" target="_blank" rel="nofollow">http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"></a> <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"/> <bean id="module5_urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> <property name="mappings"> <props> <prop key="/admin/config/index.html">admin.config.DisplayConfigListController</prop> <prop key="/admin/config/displayConfigList.html">admin.config.DisplayConfigListController</prop> <prop key="/admin/config/updateConfig.html">admin.config.UpdateConfigController</prop> </props> </property> </bean> <bean name="admin.config.DisplayConfigListController" class="com.igs.tup.config.controller.DisplayConfigListController"> <property name="configService" ref="configService" /> </bean> <bean name="admin.config.UpdateConfigController" class="com.igs.tup.config.controller.UpdateConfigController"> <property name="configService" ref="configService" /> </bean> <bean name="configService" class="com.igs.tup.config.services.ConfigServicesImpl"> <property name="configDao" ref="configDao" /> </bean> <bean name="configDao" class="com.igs.tup.config.dao.ConfigDaoImpl"> <property name="sessionFactory" ref="sessionFactory" /> <property name="targetEntityName" value="Config" /> </bean> </beans>
I am unable to upload the file.Can somebody please help me.Its urgent
[ December 17, 2008: Message edited by: amity raj ]
Consider Paul's
rocket mass heater
.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
how to upload using html or javascript?
java. lang. IllegalStateException: Neither Binding Result nor plain target object
Problem with Image display in JSP
how do i find the referring page in struts
image is not uploaded into the database
More...