Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Servlets
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:
Servlets
Where do I put RequestDispatcher dispatcher?
Michele Smith
Ranch Hand
Posts: 421
posted 11 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Where do I put
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/doUploadVideo");
It doesn't appear right here.
Thanks,
Michele
package bcc.actions; import java.io.File; import java.util.ArrayList; import java.util.Collection; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import bcc.lib.BaseDoServlet; import bcc.lib.Context; import bcc.lib.dob.Home; import bcc.lib.dob.RUserRoles; import com.bc.domain.BcTransactor; import com.bc.util.BcSQLAgent; /* * UploadVideo.java * */ import java.util.logging.Level; import java.util.logging.Logger; import org.apache.commons.fileupload.*; import java.io.*; import java.util.Iterator; import java.util.List; import javax.servlet.*; import javax.servlet.http.*; import org.apache.commons.fileupload.disk.DiskFileItem; import org.apache.commons.fileupload.disk.DiskFileItemFactory; import org.apache.commons.fileupload.servlet.ServletFileUpload; import com.bc.util.ClientHttpRequest; **************************************************************/ public class doUpdateFuneralHomeInfo extends BaseDoServlet { public Collection getAuthorizedRoles() { Collection c = new ArrayList(); c.add( RUserRoles.ADMINISTRATOR ); c.add( RUserRoles.WEB_USER ); c.add( RUserRoles.USER ); return c; } public void doAction( Context ctx, BcSQLAgent agt, HttpServletRequest req, HttpServletResponse res ) throws ServletException { try { // parse multipart request - files saved in the images folder of the web app com.oreilly.servlet.MultipartRequest multi = new com.oreilly.servlet.MultipartRequest( req,getServletContext().getRealPath("/images"), 5 * 1024 * 1024); _getState(multi, ctx); Home h = ctx.getHome( agt ); h.setName( multi.getParameter( "tbName" ) ); h.setHomeShortName( multi.getParameter( "tbSName" ) ); h.setAddress1( multi.getParameter( "tbAddress1" ) ); h.setAddress2( multi.getParameter( "tbAddress2" ) ); h.setCity( multi.getParameter( "tbCity" ) ); h.setZip( multi.getParameter( "tbZip" ) ); h.setCountry( multi.getParameter( "hidCountry" ) ); String homeCountry = h.getCountry(); if(homeCountry.equals("US") || homeCountry.equals("")) { h.setState( multi.getParameter( "tbState" ) ); } if(homeCountry.equals("CA")) { h.setState( multi.getParameter( "tbProvince" ) ); } h.setPhone( multi.getParameter( "tbPhone" ) ); h.setFax( multi.getParameter( "tbFax" ) ); h.setEmail( multi.getParameter( "tbEmail" ) ); // h.setHomeProductTax( multi.getParameter( "tbMerchandiseTax" ) ); // h.setHomeServiceTax( multi.getParameter( "tbServiceTax" ) ); // h.setHomeCashAdvanceTax( multi.getParameter( "tbCashAdvanceTax" ) ); h.setHomeOurCommitment( multi.getParameter( "homecmmtmnt" ) ); h.setVisitationEdTxt( multi.getParameter( "txtVISIT_ED_TXT" ) ); h.setFuneralEdTxt( multi.getParameter( "txtFUN_ED_TXT" ) ); h.setCommittalEdTxt( multi.getParameter( "txtCOM_ED_TXT" ) ); h.setGatheringEdTxt( multi.getParameter( "txtGAT_ED_TXT" ) ); h.setCeremonyEdTxt( multi.getParameter( "txtCER_ED_TXT" ) ); h.setFamilyGatheringEdTxt( multi.getParameter( "txtFAM_ED_TXT" ) ); h.setAVLinkname( multi.getParameter( "txtAV_LINK" ) ); h.setHomeLicense( multi.getParameter( "tbLicense" ) ); h.setAccountNum( multi.getParameter( "tbBCCNum" ) ); h.setHomeDocumentScheme( "New"); // h.setHomeQBFile( multi.getParameter( "tbQBFile" ) ); // h.setCAC( multi.getParameter( "tbCAC" ) ); // h.setPAC( multi.getParameter( "tbPAC" ) ); // h.setCoAC( multi.getParameter( "tbCoAC" ) ); // h.setEAC( multi.getParameter( "tbEAC" ) ); // h.setUAC( multi.getParameter( "tbUAC" ) ); // h.setAAC( multi.getParameter( "tbAAC" ) ); // h.setUeAC( multi.getParameter( "tbUeAC" ) ); // h.setTransferPath( multi.getParameter( "tbOutputPath" ) ); h.setNewPack( multi.getParameter( "hidNewPack" ) ); String preNum = ( multi.getParameter( "tbPNNumber" ) ); int preNeedNumLength = preNum.length(); String preNeedNumLen = Integer.toString(preNeedNumLength); h.setPreNeedNumLength(preNeedNumLen); h.setPNPrefix( multi.getParameter( "tbPNPrefix" ) ); h.setPNNumber( multi.getParameter( "tbPNNumber" ) ); String anNum = ( multi.getParameter( "tbANNumber" ) ); int atNeedNumLength = anNum.length(); String atNeedNumLen = Integer.toString(atNeedNumLength); h.setAtNeedNumLength(atNeedNumLen); h.setANPrefix( multi.getParameter( "tbANPrefix" ) ); h.setANNumber( multi.getParameter( "tbANNumber" ) ); if (!(multi.getParameter( "hidOSL" )==null)) { h.setIsOSL( multi.getParameter("hidOSL")); } if (!(multi.getParameter( "hidFOL" )==null)) { h.setIsFOL( multi.getParameter("hidFOL")); } if (!(multi.getParameter( "hidCOL" )==null)) { h.setIsCOL( multi.getParameter("hidCOL")); } if (!(multi.getParameter( "hidMFH" )==null)) { h.setIsMFH( multi.getParameter("hidMFH")); } if (!(multi.getParameter( "txtGST" )==null)) { h.setHomeGstNumber( multi.getParameter("txtGST")); } h.setVFlag( multi.getParameter("hidVAL") ); String serverName = req.getServerName(); // handle uploaded Logo File (local and Server) File f; f = multi.getFile("logo"); if( serverName.equals(ctx.getserver()) ) { if ( f != null ) { h.setLogoFile( multi.getFilesystemName("logo") ); // Grab appropriate file extension to place on the end of the logo name String fileName = f.getName(); String fileExt = fileName.substring( fileName.lastIndexOf(".") ); // rename file supplied to user to a system generated name File newFile = new File((getServletContext().getRealPath("fhfiles")) + File.separator + h.getParentId() + File.separator + h.getID() + "/images/logos/" + "Logo-" + h.getID() + fileExt); newFile.delete(); f.renameTo(newFile); //set f = null f = null; } } else // local { if ( f != null ) { h.setLogoFile( multi.getFilesystemName("logo") ); // Grab appropriate file extension to place on the end of the logo name String fileName = f.getName(); String fileExt = fileName.substring( fileName.lastIndexOf(".") ); // rename file supplied to user to a system generated name File newFile = new File((getServletContext().getRealPath("images")) + File.separator + "Logo-" + h.getID() + fileExt); newFile.delete(); f.renameTo(newFile); //set f = null f = null; } } // Logo File // handle uploaded SFGS Logo File (local and Server) File sfgs; sfgs = multi.getFile("sfgslogo"); if( serverName.equals(ctx.getserver()) ) { if ( sfgs != null ) { String fileName = sfgs.getName(); String fileExt = fileName.substring( fileName.lastIndexOf(".") ); if( fileExt.equals(".jpg") || fileExt.equals(".JPG") ) { File newFile = new File((getServletContext().getRealPath("fhfiles")) + File.separator + h.getParentId() + File.separator + h.getID() + "/images/logos/" + "sfgslogo-" + h.getID() + ".jpg"); newFile.delete(); sfgs.renameTo( newFile ); sfgs = null; } else { sfgs = null; } } } else // local { if ( sfgs != null ) { String fileName = sfgs.getName(); String fileExt = fileName.substring( fileName.lastIndexOf(".") ); if( fileExt.equals(".jpg") || fileExt.equals(".JPG") ) { File newFile = new File((getServletContext().getRealPath("images")) + File.separator + "sfgslogo-" + h.getID() + ".jpg"); newFile.delete(); sfgs.renameTo( newFile ); sfgs = null; } else { sfgs = null; } } } // SFGS Logo File // handle uploaded Video Files (local and Server) h.setOSVideoPath(multi.getParameter("hidOS_FILE")); h.setVideoPath(multi.getParameter("hidVT_FILE")); h.setAVideoPath(multi.getParameter("hidAV_FILE")); //logic for the uploaded video files (local and server) //new code added by Michele Smith on 04/13/2012. RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/doUploadVideo"); { /****************HOME WEBSITE INFORMATION*******************/ // ONLY PERFORM THE FOLLOWING IF THE HOME IS A WEB HOME!!!!!!! if( ctx.getIsWebHome( agt ).equals( "T" )) { // Specify variables to hold parameters for all checkboxes // Show Products String showProds = multi.getParameter( "cbxShowProducts" ); if (showProds == null) { showProds = "F"; } h.setHomeWebShowProducts( showProds ); // Show Services String showServs = multi.getParameter( "cbxShowServices" ); if (showServs == null) { showServs = "F"; } h.setHomeWebShowServices( showServs ); // Show Prices String showPrices = multi.getParameter( "cbxShowPrices" ); if (showPrices == null) { showPrices = "F"; } h.setHomeWebShowPrices( showPrices ); // Show Facilities String showFacs = multi.getParameter( "cbxShowFacilities" ); if (showFacs == null) { showFacs = "F"; } h.setHomeWebShowFacilities( showFacs ); // Show Personnel String showPer = multi.getParameter( "cbxShowPersonnel" ); if (showPer == null) { showPer = "F"; } h.setHomeWebShowPersonnel( showPer ); // Show Obituaries String showObits = multi.getParameter( "cbxShowObituaries" ); if (showObits == null) { showObits = "F"; } h.setHomeWebShowObits( showObits ); // Show About Us String showAboutUs = multi.getParameter( "cbxShowAboutUs" ); if (showAboutUs == null) { showAboutUs = "F"; } h.setHomeWebShowAboutUs( showAboutUs ); // Site Under Maintenance String siteMain = multi.getParameter( "cbxSiteUnderMain" ); if (siteMain == null) { siteMain = "F"; } h.setHomeWebSiteUnderMaintenance( siteMain ); /*********************CHECKBOXES COMPLETE****************************/ // Set images and accompanying text f = multi.getFile("webImage1"); if ( f != null) { h.setHomeWebImg1( multi.getFilesystemName( "webImage1")); // Grab appropriate file extension to place on the end of the logo name String fileName = f.getName(); String fileExt = fileName.substring( fileName.lastIndexOf(".") ); // rename file supplied to user to a system generated name File newFile = new File((getServletContext().getRealPath("images")) + File.separator + "WebImage1-" + h.getID() + fileExt); newFile.delete(); f.renameTo(newFile); //set f = null f = null; } h.setHomeWebTxt1( multi.getParameter( "webTxt1" )); // accompanying text f = multi.getFile("webImage2"); if ( f != null) { h.setHomeWebImg2( multi.getFilesystemName( "webImage2")); // Grab appropriate file extension to place on the end of the logo name String fileName = f.getName(); String fileExt = fileName.substring( fileName.lastIndexOf(".") ); // rename file supplied to user to a system generated name File newFile = new File((getServletContext().getRealPath("images")) + File.separator + "WebImage2-" + h.getID() + fileExt); newFile.delete(); f.renameTo(newFile); //set f = null f = null; } h.setHomeWebTxt2( multi.getParameter( "webTxt2" )); // accompanying text f = multi.getFile("webImage3"); if ( f != null) { h.setHomeWebImg3( multi.getFilesystemName( "webImage3")); // Grab appropriate file extension to place on the end of the logo name String fileName = f.getName(); String fileExt = fileName.substring( fileName.lastIndexOf(".") ); // rename file supplied to user to a system generated name File newFile = new File((getServletContext().getRealPath("images")) + File.separator + "WebImage3-" + h.getID() + fileExt); newFile.delete(); f.renameTo(newFile); //set f = null f = null; } h.setHomeWebTxt3( multi.getParameter( "webTxt3" )); // accompanying text f = multi.getFile("webImage4"); if ( f != null) { h.setHomeWebImg4( multi.getFilesystemName( "webImage4")); // Grab appropriate file extension to place on the end of the logo name String fileName = f.getName(); String fileExt = fileName.substring( fileName.lastIndexOf(".") ); // rename file supplied to user to a system generated name File newFile = new File((getServletContext().getRealPath("images")) + File.separator + "WebImage4-" + h.getID() + fileExt); newFile.delete(); f.renameTo(newFile); //set f = null f = null; } h.setHomeWebTxt4( multi.getParameter( "webTxt4" )); // accompanying text } // if ctx.getIsWebHome().equals( "T" ) String sDefaultHomeTheme = multi.getParameter( "selHomeDefaultTheme" ); if ( sDefaultHomeTheme != null) { h.setHomeTheme( sDefaultHomeTheme ); //This calls the setter for the default theme } BcTransactor t = new BcTransactor( agt ); t.addSave( h ); t.execute(); ctx.releaseHome(); // variable to store correct redirect page\ String sPage = multi.getParameter( "hidScreenName" ); if (sPage.contains("?")){ sPage =sPage+"&userid="+ctx.getUserId()+"&caseid="+ctx.getCaseId()+"&parentid="+ctx.getParentId()+"&mode="+ctx.getMode()+"&homeid="+ctx.getHomeId(); }else{ sPage =sPage+"?userid="+ctx.getUserId()+"&caseid="+ctx.getCaseId()+"&parentid="+ctx.getParentId()+"&mode="+ctx.getMode()+"&homeid="+ctx.getHomeId(); } req.getRequestDispatcher(sPage) .forward(req, res); } } catch( Exception e ) { throw new ServletException( e ); } } }
Nauman Hasan
Ranch Hand
Posts: 34
posted 11 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Not sure what you are trying to do... can you elaborate? What is the error message you get (if any)?
~Nauman
Don't get me started about those stupid
light bulbs
.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
my servlet says its unavailable in IE
file uploading through servlet
How to configure Bonecp in java project without breaking connection when more than connection
Help with Servlet Code
Need to hook two servlets together, how do I do that?
More...