Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Problem with calling servlet from jsp

843842Aug 21 2008 — edited Aug 21 2008
First off, sorry for the long post, but I felt it necessary to provide all the details instead of a "it won't work help pls" useless post.

I've been spending a lot of time looking online (Google, these forums etc) for help with this, and all I've managed to do is frustrate myself immensely. My task is fairly simple; call a servlet with my database blob retrieval code from my jsp page, and stream the file back, as a download. Now, I've already written code for this, so that's not the issue. But I've not managed to actually see my code in action, because I can never get my jsp page to call the servlet successfully.

Some additional details about the actual environment. The technologies behind the scene being used are Liferay, JBoss and Alfresco. I can't really provide much more information on this part, as the senior developer already set all this up, and is away on holidays. I can saw this for sure, there is NO localhost, and no, I cannot test on it. My project is compiled to a .war file, and uploaded to our server.

Currently, the portion of the website I'm working on consists of two portlets, both of which work fine. One portlet is an message and file uploader, the other is an admin panel to view the messages and allow the user to download the file if it exists. I determined through searching the web that downloading a file from a database using a portlet was not possible, but pretty much everything pointed to using a servlet instead. After more digging on that topic, I found this site: http://balusc.blogspot.com/2007/07/fileservlet.html , which was pretty much exactly what I was trying to do, however in practice, I couldn't get it to work.

Currently as it stands, this is what the file structure for my project looks like (simplified for space, and wrapped in code blocks to keep the formatting):
..\New Members Area\
   |- Other Folders\
   |- portlets\
      |- name\
	 |- Other Folders\
	 |- src\
	    |- web\
	       |- build\
		  |- web\
	          |  |- jsp\
	          |     |- misc jsp files
	    	  |     |- BenefitsContact\
		  |	   |- BenefitsContact jsp files
		  |	   |- BenefitsContactAdmin\
	  	  |           |- adminContact.jsp
		  |	      |- adminDone.jsp
		  |	      |- errorPage.jsp
		  |	      |- readMessage.jsp
		  |- META-INF\
		  |- WEB-INF\
		     |- Other Folders\
		     |- classes\
			|- com\
			   |- omea\
			      |- members\
				 |- portlet\
				 |  |- BenefitsContact.class
				 |  |- BenefitsContactAdmin.class
				 |- servlet\
				    |- fileServlet.class
Inside my web.xml file I've added the following:

<servlet>
<servlet-name>fileServlet</servlet-name>
<servlet-class>com.omea.members.servlet.fileServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>fileServlet</servlet-name>
<url-pattern>/file/*</url-pattern>
</servlet-mapping>


The servlet itself (called fileServlet) matches all the examples I've found online for servlets, and was generated by NetBeans 6.1 add->servlet from the right-click menu. doGet and doPost use @override, as from what I've read online, those need to be overridden in order for it to work.

Also from what I've read online, there are numerous ways to call a servlet from a jsp page, however, the one I need to use is the <a href></a> one. I've tried multiple alterations on my line of jsp code, with varying attempts, all failing.
The page, readMessage has a <a href></a> link, that's I've been using to try and call the servlet. The web address http://10.10.10.41:81/web/guest/* is the base of where everything sits.

Starting with the basics
<c:out value="${row.filename}"/><c:out value="click here"/> : nets me a "resource not found" error from liferay, trying to open the page http://10.10.10.41:81/web/guest/file
<c:out value="${row.filename}"/><c:out value="click here"/> same "resource not found" error, trying to open the page http://10.10.10.41:81/web/guest/file/id=106
<c:out value="${row.filename}"/><c:out value="click here"/> same "resource not found" error, trying to open the page http://10.10.10.41:81/web/guest/file?id=106

Following a small line of code from a post from the forums here about a similar issue, I added "${pageContent.request.contextPath}". Again, the same three, but with the pageContent bit added in.
<c:out value="click here"/> results in a link to http://10.10.10.41:81/file
<c:out value="click here"/> results in a link to http://10.10.10.41:81/file/id=106
<c:out value="click here"/> results in a link to http://10.10.10.41:81/file?id=106
All three very briefly cause the window to go blank instead of a "resource not found" error, then the doView portlet code for readMessage executes somehow, reloads the page, and I end up back where I started.

Trying <c:out value="click here"/>, <c:out value="click here"/> or <c:out value="click here"/> results in the same scenario as above.

From what I can tell, the servlet code is not executed in any of these cases, as there would be logging code in the server.log file (I'm using some unmissable log.trace() calls). I have no clue what I am missing in order to get this to work, and am pretty much at my wits end. If someone is able to point me in the right direction, I would be most appreciative.

If additional information is required, I'll do my best to reply promptly.

Thanks.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 18 2008
Added on Aug 21 2008
1 comment
975 views