LarryAndro
asked on
Out.println in Bean & Javax.servlet.jsp
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.JspWrite r'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.JspWrite r (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.deliveryservic e.scs.jsp;
import gov.vha.hvm.deliveryservic e.scs.pers istence.Da taStore;
import gov.vha.hvm.deliveryservic e.scs.pers istence.im pl.*;
import gov.vha.hvm.deliveryservic e.scs.mode l.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.js p.JspWrite r out){
DataStore ds = TransientDataStoreImpl.get Instance() ;
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...</O PTION>"); 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\servl et-api.jar and...
c:\j2re1.4.2_05\lib\ext\se rvlet.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>ja r tf servlet.jar
META-INF/MANIFEST.MF
javax/servlet/LocalStrings .propertie s
javax/servlet/http/LocalSt rings.prop erties
javax/servlet/http/HttpSer vlet.class
javax/servlet/http/NoBodyR esponse.cl ass
javax/servlet/http/NoBodyO utputStrea m.class
javax/servlet/http/Cookie. class
javax/servlet/http/HttpSes sionBindin gEvent.cla ss
javax/servlet/http/HttpSer vletReques t.class
javax/servlet/http/HttpSer vletRespon se.class
javax/servlet/http/HttpSes sion.class
javax/servlet/http/HttpSes sionBindin gListener. class
javax/servlet/http/HttpSes sionContex t.class
javax/servlet/http/HttpUti ls.class
javax/servlet/GenericServl et.class
javax/servlet/ServletInput Stream.cla ss
javax/servlet/RequestDispa tcher.clas s
javax/servlet/Servlet.clas s
javax/servlet/ServletConfi g.class
javax/servlet/ServletConte xt.class
javax/servlet/ServletExcep tion.class
javax/servlet/ServletOutpu tStream.cl ass
javax/servlet/ServletReque st.class
javax/servlet/ServletRespo nse.class
javax/servlet/SingleThread Model.clas s
javax/servlet/UnavailableE xception.c lass
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/ServletRespo nse.class
javax/servlet/ServletOutpu tStream.cl ass
javax/servlet/FilterChain. class
javax/servlet/ServletReque st.class
javax/servlet/ServletInput Stream.cla ss
javax/servlet/RequestDispa tcher.clas s
javax/servlet/ServletExcep tion.class
javax/servlet/ServletConfi g.class
javax/servlet/ServletConte xt.class
javax/servlet/Servlet.clas s
javax/servlet/GenericServl et.class
javax/servlet/UnavailableE xception.c lass
javax/servlet/http/HttpSer vletRespon se.class
javax/servlet/http/Cookie. class
javax/servlet/http/HttpSer vletRespon seWrapper. class
javax/servlet/http/HttpSes sionBindin gEvent.cla ss
javax/servlet/http/HttpSes sionEvent. class
javax/servlet/http/HttpSes sion.class
javax/servlet/http/HttpSes sionContex t.class
javax/servlet/http/HttpSer vletReques tWrapper.c lass
javax/servlet/http/HttpSer vletReques t.class
javax/servlet/http/HttpSes sionActiva tionListen er.class
javax/servlet/http/HttpSes sionAttrib uteListene r.class
javax/servlet/http/HttpSes sionBindin gListener. class
javax/servlet/http/HttpUti ls.class
javax/servlet/http/HttpSer vlet.class
javax/servlet/http/NoBodyR esponse.cl ass
javax/servlet/http/NoBodyO utputStrea m.class
javax/servlet/http/HttpSes sionListen er.class
javax/servlet/http/LocalSt rings.prop erties
javax/servlet/http/LocalSt rings_es.p roperties
javax/servlet/http/LocalSt rings_ja.p roperties
javax/servlet/http/LocalSt rings_fr.p roperties
javax/servlet/ServletRespo nseWrapper .class
javax/servlet/ServletReque stWrapper. class
javax/servlet/SingleThread Model.clas s
javax/servlet/FilterConfig .class
javax/servlet/ServletConte xtListener .class
javax/servlet/ServletConte xtEvent.cl ass
javax/servlet/Filter.class
javax/servlet/ServletConte xtAttribut eListener. class
javax/servlet/ServletConte xtAttribut eEvent.cla ss
javax/servlet/ServletReque stAttribut eEvent.cla ss
javax/servlet/ServletReque stEvent.cl ass
javax/servlet/ServletReque stAttribut eListener. class
javax/servlet/ServletReque stListener .class
javax/servlet/LocalStrings _ja.proper ties
javax/servlet/LocalStrings _fr.proper ties
javax/servlet/LocalStrings .propertie s
javax/servlet/resources/j2 ee_web_ser vices_1_1. xsd
javax/servlet/resources/j2 ee_1_4.xsd
javax/servlet/resources/XM LSchema.dt d
javax/servlet/resources/j2 ee_web_ser vices_clie nt_1_1.xsd
javax/servlet/resources/we b-app_2_3. dtd
javax/servlet/resources/we b-app_2_2. dtd
javax/servlet/resources/js pxml.xsd
javax/servlet/resources/xm l.xsd
javax/servlet/resources/we b-app_2_4. xsd
javax/servlet/resources/da tatypes.dt d
javax/servlet/resources/we b-jsptagli brary_2_0. xsd
javax/servlet/resources/js p_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.JspWrite r and so don't have access to it's println method?
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.JspWrite
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.JspWrite
Here's the top of my bean class...
package gov.vha.hvm.deliveryservic
import gov.vha.hvm.deliveryservic
import gov.vha.hvm.deliveryservic
import gov.vha.hvm.deliveryservic
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.js
DataStore ds = TransientDataStoreImpl.get
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+
}
}
The error listed for the out.println("<OPTION...</O
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\servl
c:\j2re1.4.2_05\lib\ext\se
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>ja
META-INF/MANIFEST.MF
javax/servlet/LocalStrings
javax/servlet/http/LocalSt
javax/servlet/http/HttpSer
javax/servlet/http/NoBodyR
javax/servlet/http/NoBodyO
javax/servlet/http/Cookie.
javax/servlet/http/HttpSes
javax/servlet/http/HttpSer
javax/servlet/http/HttpSer
javax/servlet/http/HttpSes
javax/servlet/http/HttpSes
javax/servlet/http/HttpSes
javax/servlet/http/HttpUti
javax/servlet/GenericServl
javax/servlet/ServletInput
javax/servlet/RequestDispa
javax/servlet/Servlet.clas
javax/servlet/ServletConfi
javax/servlet/ServletConte
javax/servlet/ServletExcep
javax/servlet/ServletOutpu
javax/servlet/ServletReque
javax/servlet/ServletRespo
javax/servlet/SingleThread
javax/servlet/UnavailableE
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/ServletRespo
javax/servlet/ServletOutpu
javax/servlet/FilterChain.
javax/servlet/ServletReque
javax/servlet/ServletInput
javax/servlet/RequestDispa
javax/servlet/ServletExcep
javax/servlet/ServletConfi
javax/servlet/ServletConte
javax/servlet/Servlet.clas
javax/servlet/GenericServl
javax/servlet/UnavailableE
javax/servlet/http/HttpSer
javax/servlet/http/Cookie.
javax/servlet/http/HttpSer
javax/servlet/http/HttpSes
javax/servlet/http/HttpSes
javax/servlet/http/HttpSes
javax/servlet/http/HttpSes
javax/servlet/http/HttpSer
javax/servlet/http/HttpSer
javax/servlet/http/HttpSes
javax/servlet/http/HttpSes
javax/servlet/http/HttpSes
javax/servlet/http/HttpUti
javax/servlet/http/HttpSer
javax/servlet/http/NoBodyR
javax/servlet/http/NoBodyO
javax/servlet/http/HttpSes
javax/servlet/http/LocalSt
javax/servlet/http/LocalSt
javax/servlet/http/LocalSt
javax/servlet/http/LocalSt
javax/servlet/ServletRespo
javax/servlet/ServletReque
javax/servlet/SingleThread
javax/servlet/FilterConfig
javax/servlet/ServletConte
javax/servlet/ServletConte
javax/servlet/Filter.class
javax/servlet/ServletConte
javax/servlet/ServletConte
javax/servlet/ServletReque
javax/servlet/ServletReque
javax/servlet/ServletReque
javax/servlet/ServletReque
javax/servlet/LocalStrings
javax/servlet/LocalStrings
javax/servlet/LocalStrings
javax/servlet/resources/j2
javax/servlet/resources/j2
javax/servlet/resources/XM
javax/servlet/resources/j2
javax/servlet/resources/we
javax/servlet/resources/we
javax/servlet/resources/js
javax/servlet/resources/xm
javax/servlet/resources/we
javax/servlet/resources/da
javax/servlet/resources/we
javax/servlet/resources/js
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.JspWrite
errr:
public static void AddTopics(java.io.Writer out) throws IOException {
DataStore ds = TransientDataStoreImpl.get Instance() ;
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");
}
}
public static void AddTopics(java.io.Writer out) throws IOException {
DataStore ds = TransientDataStoreImpl.get
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+
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
It's working, and I'm a very excited puppy!! Thanks, both...
:-) Good luck!!
public static void AddTopics(java.io.Writer out){
DataStore ds = TransientDataStoreImpl.get
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+
}
}