Thanks for the reply, kelley. I will try it later. However, what I want to
do
is to setup some application variables which are available for all users and
servlets. I am using jswdk1-0-1, not tomcat. maybe I need to switch to
tomcat instead.
Any tips to setup some application variables?
Thanks,
Leo
-----Original Message-----
From: Koszegi, Kelley [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, December 20, 2000 6:08 AM
To: [EMAIL PROTECTED]
Subject: Re: application variable
Hi Leo,
I've done something similar, but used the session instead of the
ServletContext. You can use setAttribute & getAttribute just as you've done
below. It would look like this:
servlet #1
public class start extends HttpServlet {
public void doGet(HttpServletRequest request,HttpServletResponse
response) throws IOException, ServletException {
HttpSession s = req.getSession(true);
s.setAttribute("istatus","true");
s.setAttribute("DOCPATH","c:\\attachment\\");
RequestDispatcher d =
getServletContext().getRequestDispatcher("someaddress");
d.include(request,response);
}
public void doPost(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
doGet(request, response);
}
}
servlet 2:
##################
public class index extends HttpServlet {
public void doGet(HttpServletRequest request,HttpServletResponse
response) throws IOException, ServletException {
response.setContentType("text/html");
HttpSession s = req.getSession(true);
PrintWriter out = response.getWriter();
String ob = (String) s.getAttribute("istatus");
out.println(ob);
out.close(); //close printwriter
}
public void doPost(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
doGet(request, response);
}
}
Hope that helps,
--Kelley
> -----Original Message-----
> From: Liu, Leo Huaizhen [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, December 20, 2000 12:29 AM
> To: [EMAIL PROTECTED]
> Subject: application variable
>
>
> I want to include another servlet, however, all the
> application variables
> defined in current servlet
> can not been seen the included servlet. here are some of the
> code. The line
> 'out.println((String)ob);' only
> printed out 'null'. It seemed the application variable
> 'istatus' has not
> been passed to second servlet.
> Any idea? please help.
>
> leo
>
>
> servlet #1:
>
> public class start extends HttpServlet
> {
> public void doGet(HttpServletRequest request,HttpServletResponse
> response) throws IOException, ServletException
> {
>
> ServletContext s = getServletContext();
> s.setAttribute("istatus","true");
> s.setAttribute("DOCPATH","c:\\attachment\\");
> RequestDispatcher d = s.getRequestDispatcher ("index");
> d.include(request,response);
>
> }
>
> public void doPost(HttpServletRequest request, HttpServletResponse
> response) throws ServletException, IOException
> {
> doGet(request, response);
> }
> }
>
> servlet 2:
> ##################
>
> public class index extends HttpServlet
> {
> public void doGet(HttpServletRequest request,HttpServletResponse
> response) throws IOException, ServletException
> {
> response.setContentType("text/html");
> PrintWriter out = response.getWriter();
>
> Object ob = getServletContext().getAttribute("istatus");
>
> out.println((String)ob); //?????????????????
>
> out.close(); //close printwriter
> }
>
> public void doPost(HttpServletRequest request, HttpServletResponse
> response) throws ServletException, IOException
> {
> doGet(request, response);
> }
> }
>
> ______________________________________________________________
> _____________
> To unsubscribe, send email to [EMAIL PROTECTED] and
> include in the body
> of the message "signoff SERVLET-INTEREST".
>
> Archives: http://archives.java.sun.com/archives/servlet-interest.html
> Resources:
http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html