• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

How to call a servlet from a controller

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I am new to Java development, In my project I am creating a profile for the user when they log-in to the system.

I get the general information like name, e-mail and browse (Picture), when they save the profile the detils are saved in the oracle table. But the picture is saved in the server file.

I have written a Servlet to retive the picture from the file system, I have no idea where should I written the code in the controller to retive the picture.

Here the controller code

if ("viewProfile".equals(mapping.getParameter()))
{
try
{
//
// Get Single user profile details
String pofileshotname = new String(request.getParameter("shotname"));

BVDirectoryDAO bvDirectoryDAO = new BVDirectoryDAO();
Profile bvDirectoryUserInfo = bvDirectoryDAO.getBVDirectoryUserInfo(pofileshotname);
if (bvDirectoryUserInfo != null)
request.setAttribute(Constants.BVDIRECTORY_USERINFO, bvDirectoryUserInfo);
else
return (mapping.findForward("SystemError"));

ProfileDAO virtualAcademyDAO = new ProfileDAO();
Profile virtualAcademy = virtualAcademyDAO.getVAUserProfileInfo(pofileshotname);
request.setAttribute(Constants.CURRENT_VIRTUALACADEMY_USERPROFILE, virtualAcademy);
}
catch (DAOException daoe)
{
System.err.println("Error in retriving Virtual Academy List");
daoe.printStackTrace(System.err);
return (mapping.findForward("SystemError"));
}

//
// Done
return (mapping.findForward("success"));

}

----------------------------------------------
Servelt code

public class RetrieveProfileImage extends HttpServlet
{


public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {

// Get the absolute path of the image

String pofileshotname = new String(request.getParameter("shotname"));
[ October 27, 2005: Message edited by: Giridhar Gajula ]
 
Ranch Hand
Posts: 1514
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your controller should not be doing any retrieving of data. It should use the services of the model/delegate to the model to retrieve the data. This will be just a regular Java class that the controller will call, and set the appropriate variable. After which it will be made available to the JSP for display via forwarding by the controller.
 
Ranch Hand
Posts: 783
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It also looks like you are using Struts. I would recommend learning how to develop with simple Servlets and JSPs before using a framework such as Struts. Otherwise it is kind of like trying to race a Formula 1 car without your driver's license.
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If it's saved to the filesystem, just add an image link to the view.

If the image is not stored within your webapp, you will need to stream the image. See SimpleStream at http://simple.souther.us for an example of how to do so.
 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Never Mind. I called session.invalidate() during login & that fixed the problem.

Thanks
 
It's just a flesh wound! Or a tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic