Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Out.println in Bean & Javax.servlet.jsp

Posted on 2004-10-20
6
Medium Priority
?
5,677 Views
Last Modified: 2012-05-05
I'm having a problem writing to a webpage using out.println from inside a bean class.  Below, I'm including my best conjectures and also the information that I think an expert would want.  If I'm going in a wrong direction, let me know.  Again, my need is to print to a webpage from inside a bean class.

Currently, I am usering JSP code with some embedded <% java code using out.println %>.  I want to move the <% java code %> out of the JSP, into a bean class.  But, in the bean class, out.println doesn't work.  

I have reviewed the one Experts Exchange message I can find on this topic...  'How to perform out.println() from class'... and know I can't use out.println directly in the bean.  If I understand what TimYates and JugglerW said, I have to pass into a print method I make, either java.io.Writer or javax.servlet.jsp.JspWriter's 'out' object, so the out.println method can be found.  

And, I think that's where my problem starts.  I don't seem to have all the needed javax.servlet.[...] resources I would expect. ( So, I'm probably dealing with an import or a CLASSPATH problem.)

In my class, when I try to import javax.servlet.jsp.JspWriter (see TimYates comments in other message), intellisense doesn't find javax.servlet.jsp or anything descendant.  And, this also seems to verify that javax.servlet.[...] isn't on a build path somewhere.  More on that later...

Here's the top of my bean class...

package gov.vha.hvm.deliveryservice.scs.jsp;
import gov.vha.hvm.deliveryservice.scs.persistence.DataStore;
import gov.vha.hvm.deliveryservice.scs.persistence.impl.*;
import gov.vha.hvm.deliveryservice.scs.model.domain.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.lang.*;
import java.util.Collection;
import javax.servlet.*;
public class SubscriptionCalls {
      private static String topNm;
      public static void AddTopics(javax.servlet.jsp.JspWriter out){
            DataStore ds = TransientDataStoreImpl.getInstance();      
            Collection topics = ds.getTopics(); Iterator
            iterTopics = topics.iterator();
            while (iterTopics.hasNext()){
                  Topic topic = (Topic)iterTopics.next();
                  topNm=topic.getName();
                  out.println("<OPTION name='entryTopic' value='"+topNm+"'>"+topNm+"</OPTION>");
            }
      }

The error listed for the out.println("<OPTION...</OPTION>"); line above is...

     javax.servlet.jsp cannot be resolved (or is not a valid type) for the
     parameter out of the method AddTopics

My understanding is that javax.servlet.jsp.[...' should be in either Tomcat's servlet-api.jar or in servlet.jar.  These two jar's are both in my CLASSAPATH, which includes both...

      c:\Tomcat\common\lib\servlet-api.jar    and...
      c:\j2re1.4.2_05\lib\ext\servlet.jar

Below, I have included the contents of both jar's showing that javax.servlet.jsp.[...] is not in either jar.

Here are the contents of servlet.jar...

C:\j2re1.4.2_05\lib\ext>jar tf servlet.jar
META-INF/MANIFEST.MF
javax/servlet/LocalStrings.properties
javax/servlet/http/LocalStrings.properties
javax/servlet/http/HttpServlet.class
javax/servlet/http/NoBodyResponse.class
javax/servlet/http/NoBodyOutputStream.class
javax/servlet/http/Cookie.class
javax/servlet/http/HttpSessionBindingEvent.class
javax/servlet/http/HttpServletRequest.class
javax/servlet/http/HttpServletResponse.class
javax/servlet/http/HttpSession.class
javax/servlet/http/HttpSessionBindingListener.class
javax/servlet/http/HttpSessionContext.class
javax/servlet/http/HttpUtils.class
javax/servlet/GenericServlet.class
javax/servlet/ServletInputStream.class
javax/servlet/RequestDispatcher.class
javax/servlet/Servlet.class
javax/servlet/ServletConfig.class
javax/servlet/ServletContext.class
javax/servlet/ServletException.class
javax/servlet/ServletOutputStream.class
javax/servlet/ServletRequest.class
javax/servlet/ServletResponse.class
javax/servlet/SingleThreadModel.class
javax/servlet/UnavailableException.class

Here are the contents of servlet-api.jar...

C:\Tomcat\common\lib>jar tf servlet-api.jar
META-INF/
META-INF/MANIFEST.MF
javax/
javax/servlet/
javax/servlet/http/
javax/servlet/resources/
javax/servlet/ServletResponse.class
javax/servlet/ServletOutputStream.class
javax/servlet/FilterChain.class
javax/servlet/ServletRequest.class
javax/servlet/ServletInputStream.class
javax/servlet/RequestDispatcher.class
javax/servlet/ServletException.class
javax/servlet/ServletConfig.class
javax/servlet/ServletContext.class
javax/servlet/Servlet.class
javax/servlet/GenericServlet.class
javax/servlet/UnavailableException.class
javax/servlet/http/HttpServletResponse.class
javax/servlet/http/Cookie.class
javax/servlet/http/HttpServletResponseWrapper.class
javax/servlet/http/HttpSessionBindingEvent.class
javax/servlet/http/HttpSessionEvent.class
javax/servlet/http/HttpSession.class
javax/servlet/http/HttpSessionContext.class
javax/servlet/http/HttpServletRequestWrapper.class
javax/servlet/http/HttpServletRequest.class
javax/servlet/http/HttpSessionActivationListener.class
javax/servlet/http/HttpSessionAttributeListener.class
javax/servlet/http/HttpSessionBindingListener.class
javax/servlet/http/HttpUtils.class
javax/servlet/http/HttpServlet.class
javax/servlet/http/NoBodyResponse.class
javax/servlet/http/NoBodyOutputStream.class
javax/servlet/http/HttpSessionListener.class
javax/servlet/http/LocalStrings.properties
javax/servlet/http/LocalStrings_es.properties
javax/servlet/http/LocalStrings_ja.properties
javax/servlet/http/LocalStrings_fr.properties
javax/servlet/ServletResponseWrapper.class
javax/servlet/ServletRequestWrapper.class
javax/servlet/SingleThreadModel.class
javax/servlet/FilterConfig.class
javax/servlet/ServletContextListener.class
javax/servlet/ServletContextEvent.class
javax/servlet/Filter.class
javax/servlet/ServletContextAttributeListener.class
javax/servlet/ServletContextAttributeEvent.class
javax/servlet/ServletRequestAttributeEvent.class
javax/servlet/ServletRequestEvent.class
javax/servlet/ServletRequestAttributeListener.class
javax/servlet/ServletRequestListener.class
javax/servlet/LocalStrings_ja.properties
javax/servlet/LocalStrings_fr.properties
javax/servlet/LocalStrings.properties
javax/servlet/resources/j2ee_web_services_1_1.xsd
javax/servlet/resources/j2ee_1_4.xsd
javax/servlet/resources/XMLSchema.dtd
javax/servlet/resources/j2ee_web_services_client_1_1.xsd
javax/servlet/resources/web-app_2_3.dtd
javax/servlet/resources/web-app_2_2.dtd
javax/servlet/resources/jspxml.xsd
javax/servlet/resources/xml.xsd
javax/servlet/resources/web-app_2_4.xsd
javax/servlet/resources/datatypes.dtd
javax/servlet/resources/web-jsptaglibrary_2_0.xsd
javax/servlet/resources/jsp_2_0.xsd

So, what is my problem?  Why can't I write to out.println in my bean class?  Is it because I don't have access to javax.servlet.jsp.JspWriter and so don't have access to it's println method?  
0
Comment
Question by:LarryAndro
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
6 Comments
 
LVL 35

Expert Comment

by:TimYates
ID: 12362566
Try:

     public static void AddTopics(java.io.Writer out){
          DataStore ds = TransientDataStoreImpl.getInstance();    
          Collection topics = ds.getTopics(); Iterator
          iterTopics = topics.iterator();
          while (iterTopics.hasNext()){
               Topic topic = (Topic)iterTopics.next();
               topNm=topic.getName();
               out.write("<OPTION name='entryTopic' value='"+topNm+"'>"+topNm+"</OPTION>\n");
          }
     }
0
 
LVL 35

Expert Comment

by:TimYates
ID: 12362574
errr:

     public static void AddTopics(java.io.Writer out) throws IOException {
          DataStore ds = TransientDataStoreImpl.getInstance();    
          Collection topics = ds.getTopics(); Iterator
          iterTopics = topics.iterator();
          while (iterTopics.hasNext()){
               Topic topic = (Topic)iterTopics.next();
               topNm=topic.getName();
               out.write("<OPTION name='entryTopic' value='"+topNm+"'>"+topNm+"</OPTION>\n");
          }
     }
0
 
LVL 35

Accepted Solution

by:
TimYates earned 1200 total points
ID: 12362578
Heh, last try:

     public static void AddTopics(java.io.Writer out) throws java.io.IOException {
          DataStore ds = TransientDataStoreImpl.getInstance();    
          Collection topics = ds.getTopics(); Iterator
          iterTopics = topics.iterator();
          while (iterTopics.hasNext()){
               Topic topic = (Topic)iterTopics.next();
               topNm=topic.getName();
               out.write("<OPTION name='entryTopic' value='"+topNm+"'>"+topNm+"</OPTION>\n");
          }
     }
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 8

Assisted Solution

by:kiranhk
kiranhk earned 800 total points
ID: 12362631
include jsp-api.jar in the classpath
this is found under  jakarta-tomcatXXXX\common\lib folder where xxxx is ur tomcat version
then u can compile the files
0
 
LVL 1

Author Comment

by:LarryAndro
ID: 12363058
It's working, and I'm a very excited puppy!!  Thanks, both...
0
 
LVL 35

Expert Comment

by:TimYates
ID: 12367301
:-)  Good luck!!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

While opting for any web-to-print solution, you need to discuss with your team and some of your end users and know their opinions about your decisions. In this article we list down some questions you need to ask yourself.
Whoever said that “a picture is worth one thousand words” observed a fact that can dramatically affect your marketing success. Most people tend to learn visually, so many publishers commonly acknowledge the effectiveness of visual learning by using…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question