How to use Servlet Context

Has any one used ServletContext 's setAttribute() method to store parameters in one JSP and access them in another JSP.
I want to replace hy Hidden Parmeters with this method, so that I can hide all my parameter names and their values in the HTML page, when an end user uses View Source option on a browser.
If any one has that code available,please post that so that I can avoid all this coding and testing phase
Thanks
Suresh

It is actually very easy, and I use it often, for example to track the user's login.
In one jsp page you use:
<% session.setAttribute("someName", anObject); %>
Where "someName" is a string with the name you want to give to the object (choose different names for different objects) and aObject can be any object that is a descendant of Object (that means everything but primitive types, to store those use wrappers from the java.lang package, like Integer, Float, etc).
Now, to retrieve in other pages, you just use the getAttribute method and cast to object:
<% AnObject otherObject = (AnObject) session.getAttribute("someName"); %>
A note of caution: The object will remain until session is invalidated (manually or timed out) or the object is expressly removed. If no object with the given name is found, the jsp will throw a NullPointerException, which you are not obligated to catch, but I strongly suggest you do, because there will be a time when that exception is thrown no matter how well coded are your jsp's (for example when a session times out and the user clicks on refresh on some page that asks for an object, etc).
Good Luck.
Ylan

Similar Messages

  • How to use a context between two components at the runtime

    Hi Experts,
    My Web dynpro component is over the Generation limit (size of generated load is > 2 MB) so it always gets Warning when I active it. That why I have separated my application into two components and use the ViewContainerUIElement in order to show views of each other.
    In the application, I use also the TimeTrigger to refresh pages, all views have a TimeTrigger and the DELAY property of TimeTriggers is bounden into the same context attribute. I use a component to set up (change) the value of context attribute that is mapped with the Delay property. I want to change the Delay value on a component and other component will understand the changing.
    My problem is how I can use the same context attribute between components at the runtime?
    Let give me your advice on this.
    Many thanks,
    Ken

    Hi Ken,
    You can use [external context mapping|https://cw.sdn.sap.com/cw/docs/DOC-27901] to share data between two or more components using context.
    Thanks,
    Duy

  • How to use send context in ccBPM

    Hello,
    I am trying my first BPM process. I am using the send step while I need to specify the receiver using send context. The value of the send context should be:
    The send context is a freely definable string, which you specify in the send step. You query the send context in a condition in the receiver determination in the Integration Directory. You must specify the send context to be able to send messages from the same message interfaces to different receivers in different send steps.
    My questions is how to query the send context in condition of the receiver determination (RD). The condition  of RD is basically variable operator value, while variable could be field of the payload or context object. I don't see how to query the send context in a RD condition. Can somebody explain it?
    Thanks
    Jayson

    Hi Jayson
    You must specify the send context to be able to send messages from the same interface to different receivers in different send steps.
    Check this
    http://help.sap.com/saphelp_nw04/helpdata/en/11/13283fd0ca8443e10000000a114084/content.htm
    Thanks
    Gaurav

  • 9iAS server how to use servlet

    While using 9ias there are two types of running the application one through cgi and another through servlet.
    The default examples are in cgi. while i am running through cgi everything is fine whereas if i use servlet i am unable to run or proceed and error is raised as even though i follow all the steps given in ur documentation.
    how to proceed need a help very urgent.

    Go to the Forms page on OTN: http://www.oracle.com/technology/products/forms/index.html
    1. How do I know if I'm using the Forms listener or the Forms listener servlet?
    If you are using port 9000, then you are not using the Forms Listener Servlet architecture.
    2. How do I configure the 9iAS server to use the Forms listener servlet and listen for forms requests via HTTP?
    From Forms 9i and onwards, the Application Server installer does all of the hard work for you. In 6i, you have to do some yourself.
    Click on the All Papers link for Forms 6i. There you will find a document that describes the Forms Listener Servlet setup. (Do text search for "servlet" on that page to find it.)

  • How to use   spring context  in sca

    hi can anyone tell me how to use the spring context in bpel and how the functionality of spring context in service composite architecture(sca)

    Thanks Arun Pareek
    Hope u will also send me the link and tell me how to expose the bpel as webservice and how to connect the multiple bpel process with mediator.Sorry for troubling u much times (hope u don't mind ).
    If u don't mind in other way can i ask u r phone number as i need to talk with u ( if u don't mind only)and i will call to u only when u feel free.

  • Wondering how to use the "context" information

    I was looking at some of my events and saw that some of them have information under the Context section and some don't. 2 questions about this:
    1) What is it used for?
    2) If I am sending all events to monitoring console, why would it be coming over encryped?

    IIRC, the context info (which was once called the context buffer, BTW) provides a snippet of the packet(s) that triggered the alarm.
    It is only used for certain signatures (the Buffer Overflow-related ones use it a lot) to aid with alarm validation, or that's how we use it at least.
    As for whether or not it's "encrypted" when you receive it in MC, I can't begin to suggest what you’re seeing. Perhaps it's just binary data captured from a packet that, by its nature, looks like encrypted data?
    Care to provide more info (i.e. - SigID and a copy of the context message)?
    Alex Arndt

  • How to use Servlets with O8i on RH Linux 6.2 ???

    I'm using apache Jserv 1.1.2 to run my servlets all my JDBC programs work fine and other servlets too but only JDBC servlets give this message
    "SQLException caught Io exception: The network adapter could not
    established the connection"
    Can someone tell me How to configure JSERV to make connection ?

    Hi there,
    If I understand correctly you are running Jserv and Apache to connect to an Oracle 8i db on a remote machine. If you are getting the "network adapter" error make sure the listener is running on the remote machine (lsntrctl start -- lsntrctl status, or something like that from bash shell). Also make sure SQLNet is configured properly. Try connecting from a machine with SQL Plus. If this works and the listener is running you should be in business.
    Best
    Scott ([email protected])
    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by CSL ():
    I'm using apache Jserv 1.1.2 to run my servlets, a remote database on O8i on linux. all my JDBC programs work fine and other servlets too(with no JDBC) but only JDBC servlets give this message
    "SQLException caught Io exception: The network adapter could not established the connection"
    Can someone tell me How to configure JSERV to make connection ?<HR></BLOCKQUOTE>
    null

  • How to use servlets in portal web application in Weblogic Portal 4.0

    We are developing a Portal Web application using Weblogic Portal 4.0 where in we
    have the following scenario. one JSP in webflow of a portlet calls the PipeLine
    which does some processing and calls the servlet which is having the typical download
    functionality. The servlet is supposed to read the data from the pipeline session
    and create a CSV String that is dumped to the client browser. The problem is even
    we are doing response.setContentType("application/save") in the servlet it is
    still displaying the content as html in the portlet. I guess since all our request
    are send to the webflow contolling servlet and it is setting the content type
    and hence our servlet is not working. How do I solve this problem? Thanks Yogesh

    Hi Renu
    Please go through the SAP Content Management here you find the documents related to Wab page Compoer and knowledge mangement. Also search for article / blog for more details.
    [http://www.sdn.sap.com/irj/sdn/nw-ecm|http://www.sdn.sap.com/irj/sdn/nw-ecm]
    Hope it will helps
    Best Regards
    Arun Jaiswal

  • How to use Servlet

    I have installed JRun 4 Web Server and Java 2 SDK, SE v1.4.1_01. When i import servlet import javax.servlet.*;There is an error message.
    Package javax.servlet does not exist.
    Please help me, maybe i haven't had package javax.servlet. What do i need to install?

    for servlet development, u can either use two kinds of servlet develpment. Tomcat or J2EE RI. If u r using tomcat, then the servlet.jar will be at common/lib, if J2EE Ri, u will find a j2ee.jar to execute servlet. U must set ur classpath in your system to the location of the servlet.jar or j2ee.jar. u can either set it in control panel --> system --> advanced--> environment variable --> system variables. or by dos promptcommand

  • How to use servlets and JSP for my homepage?

    servlets and JSP are server-side program. If my homepage is on some web-hosting websites, can I upload the servlets and JSP to run it? if possible, where can I find such a web-hosting place?
    sraiper

    Not many hosts offer JSP or Servlet support (and some do but then stop and never give you a refund, grrrrrrr!!!!).
    Also, ones that do support it can often be more expensive. There are some free ones but all the one's I've come across have problems that made them unsuitable for my needs.
    Here is a list of hosts that support Java:
    http://www.thejspbook.com/resources/category.jsp?id=1005&name=JSP+web+hosting
    I can't comment on any from that list, however I use http://www.positive-internet.com they are a bit pricey but they have excellent support and are always happy to help with any Tomcat (the JSP/Servlet server they use)configuration issues or needs that you may have.

  • How ot use servlet as the element of portlet?

    I am newbie for weblogic portal. I have tried to created a testing
    portlet with content.jsp, works fine.
    Then I tried to create a servlet, compiled it, got the class file.
    I put that class file name in the content URL. To my supprise, the
    front end shows the binary code that class, instead of call it and
    return what it suppose to return.
    Any suggestion are highly welcome.
    Thanks in advance
    Jack

    Jack,
    The portal framework works based on server-side includes. When you specify the
    contentURL on the EBCC, this means that the content of that JSP will be embeded
    on the main source servlet. I think the result that you get was the normal behavior
    that should happen. The interpreter found a "text" code and simply put it in out.println("the
    binary text").
    Did you get?
    I gess I help you,
    Edoardo Boechat
    "Russell Teabeault" <reply to newsgroups> wrote:
    Jack,
    In the ContentURL field in the EBCC input the servlet path. For example
    I
    had this in my web.xml:
    <servlet>
    <servlet-name>HelloWorld</servlet-name>
    <servlet-class>examples.sampleportal.HelloWorldServlet</servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name>HelloWorld</servlet-name>
    <url-pattern>/helloworld/*</url-pattern>
    </servlet-mapping>
    In the ContentURL field I put /helloworld.
    Hope this helps.
    russ
    "jack" <[email protected]> wrote in message
    news:[email protected]..
    I am newbie for weblogic portal. I have tried to created a testing
    portlet with content.jsp, works fine.
    Then I tried to create a servlet, compiled it, got the class file.
    I put that class file name in the content URL. To my supprise, the
    front end shows the binary code that class, instead of call it and
    return what it suppose to return.
    Any suggestion are highly welcome.
    Thanks in advance
    Jack

  • How to use Servlet 2.4 with Netweaver Developer Studio 7.0?

    Hello,
    When I define my web.xml as follows:
    <!DOCTYPE web-app version="2.4"
    xmlns="http://java.sun.com/xml/ns/j2ee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
    http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
    I get an error in french: "La DTD du type de lélément racine "" doit se terminer par '>'."
    Saying that the DTD of type of root element must end with '>'     
    How can I solve this error?
    Thanks for your help,
    Tanguy Mezzano

    Hi,
    Tanguy Mezzano wrote:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE web-app version="2.4"
    xmlns="http://java.sun.com/xml/ns/j2ee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
    http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" >
    There is a  " (double quote missing in the xsi:schemaLocation attribute. This is the reason. I am guessing that you may have tried manually editing this web.xml file and may not have correctly edited it.
    To correct the <? xml ?> and <!DOCTYPE> tags - please openup a blank Web Module Project and copy these two tags only from the web.xml and overwrite the same tags in your web.xml.
    Hope that this helps.
    Thanks.
    p256960.

  • Servlet Context problem.

    have two classes, one is a servletcontextlistner implementation and another one is the actual servlet that will call the first class.
    I am trying to have a counter in a servlet that keeps track of how many users have used the servlet. I like to store that in a servletcontextlistener and then call the counters value in the servlet. and also update that counters value.
    how can I do this ? are there any good examples that you know ? please help, as i have been stuck on this for manny hours.
    ServletContextListner implementation.
    public class counterContextListener implements ServletContextListener{
    String initialValue = "0";
    public counterContextListener(){}
    public void contextDestroyed(ServletContextEvent event){}
    public void contextInitialized(ServletContextEvent event){
    ServletContext context = event.getServletContext();
    context.setAttribute("countername", initialValue);
    public static String getCounterValue(ServletContext context) {
    String value = (String)context.getAttribute("countername");
    if (value == null) {
    value ="0";
    return(value);
    }//getCounterValue
    } // end of class
    Servlet
    public void doPost(HttpServletRequest req, HttpServletResponse res) throws
    ServletException, IOException{
    con = null;
    res.setContentType("text/plain");
    ServletInputStream sis = req.getInputStream();
    DataInputStream dis = new DataInputStream(sis);
    String username = dis.readUTF();
    dis.close();
    PrintWriter out = res.getWriter();
    System.out.println("The user has come:"+username+" " +count_users);
    //Using servlet context to get the current counter
    ServletContext context = getServletContext();
    String counter = getCounterValue(context); // passing context object.
    Error
    C:\Program Files\Apache Group\Tomcat 4.1\webapps\mudServlet>javac mudServletTTT.java
    mudServletTTT.java:36: cannot resolve symbol
    symbol : method getCounterValue (javax.servlet.ServletContext)
    location: class mudServletTTT
    String counter = getCounterValue(context);
    ^

    Why would you make the Context Listener also responsible for keeping track of the counts?
    1st of all, you are doing this inside the Servlet:
    String counter = getCounterValue(context); // passing context object.
    But the servlet does not have a mehtod called getCounterValue. You need to call the CounterContextListener's method, which means you have to create one:
      CounterContextListener ccl = new CounterContextListener();
      String counter = ccl.getCounterValue(context);Second, why give the counter context listener two jobs that it doesn't need? You should make a new object - a Counter class:
    public class Counter {
      private int count;
      public Counter() { this(0); }
      public Counter(String initialValue) {
        this(Integer.parseInt(initialValue);
      public Counter(Integer initialValue) {
        this(initialValue.intValue());
      public Counter (int initialValue) {
        count = initialValue;
      public Integer getCount() { return new Integer(count); }
      public void increment() { addCount(1); }
      public void decriment() { addCount(-1); }
      public void addCount(int amountToAdd) {
        count = count + amountToAdd;
    }Then in your context listener, all you do is add one of these to the context:
    public class CounterContextListener implement ServletContextListener {
        public void contextInitialized(ServletContextEvent sce) {
            ServletContext context = sce.getServletContext();
            Counter counter = new Counter();
            context.setAttribute("counter", counter);
        public void contextDestroyed(ServletContextEvenet sce) {
        }In your servlet, you get the counter from the context, get the count, and increment it if you want to:
    public void MyServlet exctends HttpServlet {
        public void doPost( ... ) ... {
            ServletContext context = this.getServletContext();
            Counter counter = context.getCounter();
            int count = counter.getCount();
            counter.increment();
    }

  • Is WL cluster servlet-context ?

    Hi
              I wish to use servletContext object to cache
              value objects on a server which is in a clustered env.
              Is WL cluster servlet-context? Will I face any problems if I use servlet-context for caching purpose?
              Your feedback on this query is greatly appreciated.
              Thanks
              Jery
              

    Jery,
              ServletContext is not serializable. Use HTTPSessions to store your value objects.
              Jery Vincent wrote:
              > Hi
              >
              > I wish to use servletContext object to cache
              > value objects on a server which is in a clustered env.
              >
              > Is WL cluster servlet-context? Will I face any problems if I use servlet-context for caching purpose?
              >
              > Your feedback on this query is greatly appreciated.
              >
              > Thanks
              > Jery
              

  • How can I get the servlet Context from a WebService Implementation?

    I have made a webservice endpoint, using the conventional way (WSDL->wsimport->Java interface->implementation) . I need to get the servlet context below the implementation class. I haven't found any way to get the servletContext though. Any clues? Any help will be greatly appreciated.

    yes  i can found the words's unicode form Cmaps where may be at the type of tounicde and another Cmaps table just like "Adobe-GB1-GBK-EUC" ,but when the word dont have either of them how can i do? when i write a chinese word "一",it just the winansi encoding ,  there is not Cmap for me to use to change the "G208f" to the word "一"'s unicode value.
                   best wishes      thank you very much

Maybe you are looking for

  • Error message on install no printer port could be assigned

    I have installed Acrobat 7.0 professional on my new windows 7.0 laptop. On install an error msg says "No rinter port could be assigned." I have tried a couple times and no luck. Any way to assign a pdf printer port manually? thanks

  • Bex browser in NW04s

    Hi All, SAP recommends that there will be no need to use BEx browser in BI 7.0(NW04s). BEx browser can be accessed using Portal. Does anybody know how to replicate BEx browser in Portal. I have tried using 'Role upload' option. But not all features o

  • WLS5.1 (Sp5)/Netscape 3.6 & Server Side Includes

    We are trying to dynamically create a reference to a server side           include(ssi) in a JSP rendered           by the Weblogic servlet engine. Unfortunately, the combination of WLS and           netscape is treating the dynamically generaetd ssi

  • Brush Cursor rotation while painting?

    I am using a Wacom Cintiq with Wacom's Art Pen (Art Pen allows PS bushes to read full rotation). When I hover over and rotate my pen I can see the Brush Cursor rotate and move but when I place a stroke down the cursor does not move or rotate with the

  • System to slow, slower than ubuntu can you help

    HI my system is too slow can you help, it takes to start any program about 20s, even ubuntu is faster. I tryed various X window managers[icewm,gnome,kde] it is still slow.