Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to call a servlet from a controller

 
Giridhar Gajula
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • 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 ]
 
Bosun Bello
Ranch Hand
Posts: 1511
  • Mark post as helpful
  • send pies
  • 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.
 
Paul Bourdeaux
Ranch Hand
Posts: 783
  • Mark post as helpful
  • send pies
  • 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.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • 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.
 
Barun Saha
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Never Mind. I called session.invalidate() during login & that fixed the problem.

Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic