How to use session in webservice?

In C#, can use session variable in a webservice object.
How to use session in Java webservice?
Who can give me a example?
Thanks a lot

Did I use session in a wrong way?No, you are using the session correctly. The code looks fine.
Check
- your spelling of the attribute names - obviously they must match
- the ids of the sessions you get both times: session.getId(). If they have different ids, then most probably the session is being lost somewhere.
There are a number of reasons to lose a session. If you close the browser, invalidate the session in code, or lose the cookie recording the id. This happens when you change from https to http, so a session can be lost that way.
The session is normally maintained by session cookies. If you close your browser you lose the cookie. If you have disabled cookies on your machine then it also might not work.
In cases such as that you should be using the method response.encodeURL() to maintain the session for you in any hyperlinks you produce. Struts normally handles that for you though if necessary.
Hope this helps,
evnafets

Similar Messages

  • How to use session object in jsp

    hi all
    marry christmas
    can anyone plz tell me how to use session obect in jsp
    rachna
    Message was edited by:
    rachna_arora82

    hi rachna,
    JSP has a default(implicit) session object...... use the getSession(true) method on the session object and then going u can either get or set attributes depending on the requirement
    That was in general and now with the issue u have got..... what u can do is that the u can create session for every user who logs in and when he/she tries to login again then u can probably check for the existing session object in the JSP and perform the logic as required..... any clarifications plzzzzzzz let me know
    Thanks n Regards
    Naveen M
    Message was edited by:
    Novice_inJAVA
    Message was edited by:
    Novice_inJAVA

  • How to use Session scope in jsp page

    Hello, I have login form, where user provides username and password. Then click on submit, it will forward to validation.jsp. Where it will check in database make sure username and password exit. Now i can also retrive accountid of perticular user. I want to put that username and accountid in session scope. so all other pages can use that username and accountid. How can i do that. I'm new at this, so please provide me example too. Here is my code for login.jsp and validation.jsp..
    Validation.jsp
    <%@ page import="java.util.*" %>
    <%@ page import="java.sql.*" %>
    //String name = request.getParameter( "username" );//
    //session.setAttribute( "accountID",accountID );//
    <%
    String connURL = "jdbc:oracle:thin:@orca.csc.ncsu.edu:1521:ORCL";
         Connection conn = null;
         Statement stmt = null;
         ResultSet rs = null;
    Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
    conn = DriverManager.getConnection(connURL, "vapatel","pjdas");
    stmt = conn.createStatement();
    String user=request.getParameter("userName");
    String password=request.getParameter("password");
    boolean entrance=false;
    stmt.excuteQuery("SELECT AccountID From Password WHERE USERNAME='"+user+"'");
    rs = stmt.executeQuery("SELECT * FROM Password WHERE USERNAME='"+user+"' AND PASSWORD='"+password+"'");
    while(rs.next()){
    String dbUser = rs.getString("USERNAME");
    String dbPassword= rs.getString("PASSWORD");
    if ((user.equals(dbUser)) && (password.equals(dbPassword))){
    entrance=true;
    if (entrance==true){%>
    <jsp:forward page="form.jsp"/>
    <%}
    else{%>
    <jsp:forward page="login.jsp"/>
    <%}
    %>

    hi,
    to put something into session scope in a jsp page use:
    session.setAttribute("counter", Integer.toString(5));to retrieve is from a jsp page use:
    String counterAttribute = (String)session.getAttribute("counter");

  • How to use session variable in JSP function  & How to use both JSP  Servlet

    Hi,
    I am new to JSP and servlets
    Still I am devloping a website in JSP. I am not mixing JSP with servlets, but I do create Java files for bean, logic and database works.
    I try to keep the hard coding part out of JSP.
    I dont how to use both JSP and Servlets in combination.
    Hence If needed I write some functions in JSP.
    but it gives me error
    +<%! public void abc()+
    +{+
    int intUserId = Integer.valueOf((Integer) session.getAttribute("MySession_UserID"));
    +}+
    +%>+
    Saying cannot find symbol session
    1) So can u please tell how can I access session variables within JSP function
    2) And also give me some links/tutorials about useing both JSP and Servlets in combination.
    Thanks
    Venkat

    The application architecture when you use Servlets and JSP in a standard MVC pattern is explained here (under the heading "Integrating Servlets and JSP Pages") and here ...

  • How to use session tracking

    i am making shopping mall project .
    ist page conatins list of product avaiale
    2nd page contains list of manufacturuer avaible
    problem:-
    i want to display on 3rd page the product seleted by user in 1st page
    i used session tracking concept.but problem is the value is coming null in third page
    please tell me how to solve my problem

    If it is like a shopping cart, I suggest you to look for a good shopping cart examples available plenty online.
    But if its just about keeping session variables and using them the following works.
    Test with a simple example. Have three jsp files like a.jsp, b.jsp and c.jsp.
    put the following in a.jsp
    <% session.setAttribute("Mobile","Nokia");%>
    <%=session.getAttribute("Mobile")%>
    <a href="b.jsp">Go to B.jsp</a>Print the value of session variable - <%=session.getAttribute("Mobile")%> in b.jsp and c.jsp
    And in b.jsp have a link to c.jsp and so on. Once you set a session variable, it lives as long as your session doesnt expire.
    Try it. and also look for more session tracking examples online.
    Message was edited by:
    passion_for_java

  • How to use session cookie property of System object?

    Hi all,
    I have searched all over the SDN but didnt get anything relevent so here i am posting my query...
    My scenario is as follows:
    I have created a KM document iview that launches an HTML page, on click of button of HTML page a VC iview is launched. On this iview i have a button that hits BI query.
    PS: A system object is created for the connectivity bet portal and backend BI server.
    PS: i have configured SSO between portal and backend.
    Now when i click on button on iview that fetches the data from backend, i am asked for authentication pop-up, although i have configured SSO why i am asked to enter UID and PWD again??
    In system object there is a property named
    <b>"session cookie = MYSAPSSO2"</b>
    So should i use this property so that cookie will get transfered from one session to other session when i click button on iview??
    If yes then HOW??
    Is there any other setting remained in Visual Admin?? or Backend or portal?
    What could be the missing??
    PS: User id are same on portal & backend.
    Any help will be highly appreciated...
    Regards,
    Ameya
    Thanks in advance
    Message was edited by:
            Ameya Pimpalgaonkar
    null
    Message was edited by:
            Ameya Pimpalgaonkar

    Hi Ameya,
    I do not know the exact answer.However you should look for something called JSESSION ID.
    Have a look at the thread:
    Re: Problems Using Application Integrator for BSP Application
    Reg SSO Logon Tickets and Browser sessions
    How to use jsessionid while making HTTP calls??
    Hope you find something which can help you.
    Regards
    Atul Shrivastava

  • How to use Session Broker ? (Where to add Session Broker Code)

    Hi all,
    My requirement is, I have to use two different database session in one Top Link.
    I know it can be done using Session Broker, but where actually I need to add that code ? I am using JDeveloper 10.1.2.0.0(Build 1811) as i need to implement this in a BPEL process. Is it possible use Session Broker with this version , if so how to do that ?
    Thanks in advance,
    Anant.

    Hello Anant,
    Not sure what code you are refering to. Using a SessionBroker is similar to how you would use a regular session, and can be configured using sessions.xml or through java code. If you are using java code, you would do this where ever you first acquire the sessionbroker and login.
    Please refer to the docs on what it is and how it is used:
    http://download-west.oracle.com/docs/cd/B25221_04/web.1013/b13593/sesun007.htm#CACGDDHE
    The docs are for TopLink 10.1.3, and though I think TopLink 10.1.2 (9.0.4.5) is what ships with Jdev 10.1.2, they should still apply.
    Best Regards,
    Chris

  • How to use session in Struts

    Hello, there:
    It's a simple question.
    I have a web app which has a login page, in its action class I create an object, user, and save it into session by using request.getSession(true).setAttribute("user", user).
    In another action class, I want to use the info of user then I use request.getSession(true).getAttribute("user"); however, the returned object is NULL. Did I use session in a wrong way?
    Thanks,
    Sway

    Did I use session in a wrong way?No, you are using the session correctly. The code looks fine.
    Check
    - your spelling of the attribute names - obviously they must match
    - the ids of the sessions you get both times: session.getId(). If they have different ids, then most probably the session is being lost somewhere.
    There are a number of reasons to lose a session. If you close the browser, invalidate the session in code, or lose the cookie recording the id. This happens when you change from https to http, so a session can be lost that way.
    The session is normally maintained by session cookies. If you close your browser you lose the cookie. If you have disabled cookies on your machine then it also might not work.
    In cases such as that you should be using the method response.encodeURL() to maintain the session for you in any hyperlinks you produce. Struts normally handles that for you though if necessary.
    Hope this helps,
    evnafets

  • How to use session state protection

    I use Apex 3.2.1
    I access my site by a url passing a parameter like this : f?p=101:1:0::::ITEM1:1234567. There is no login and password to access the site.
    The value of the parameter ITEM1 is the authorization of the first page, with a database function for the verification.
    To secure my site I want to use session state protection so, I enabled it , then I defined "Arguments Must have checksum" for the page 1.
    Now , when i try to acces my site with the same url it does not work.
    it is the first time a try to use session state protection, could someone tell me what's wrong?

    Hi user5719906,
    I would suggest that as you need to pass an item and are unable to generate a checksum as you are not yet logged in, that you will need to allow arguments without checksum for this page.
    This could be a bit of a hole in your security, but as long as you know it is there and clear the cache for all pages that you branch to, you should be able work around it.
    The issue is that a malicious user can set page and application items via the url to an unsecured page.
    Regards
    Michael

  • How to use Oracle BIP Webservices using JAX-WS

    Hi everyone,
    Has anyone trieed invoking BI publisher web services using JAX-WS. I tried with Apache Axis technology as per the documentation [http://download.oracle.com/docs/cd/E10415_01/doc/bi.1013/e10416/bip_webservice_101331.htm] and it worked fine but now I have to use JAX-WS. Also, anyone has ideas about which one is better to use Apache Axis or JAX-WS ? Can we create stub classes using JAX-WS simply by a command as in Axis ?
    export CLASSPATH="D:/bin/axis-1_4/lib/axis.jar;D:/bin/axis-1_4/lib/jaxrpc.jar;D:/bin/axis-1_4/lib/saaj.jar;D:/bin/axis-1_4/lib/commons-logging.jar;D:/bin/axis-1_4/lib/commons-discovery.jar;D:/bin/axis-1_4/lib/wsdl4j.jar"echo $CLASSPATH
    java org.apache.axis.wsdl.WSDL2Java PublicReportService.wsdl
    Please put some light in this regard
    Thanks
    -Sookie

    If your final goal is to use BIP Webservices, then I'd suggest you to use JDeveloper and
    create a webservice proxy client which is automatically created by Jdeveloper from the BIP WSDL xml file.
    In OBE there are a couple of examples how to obtain it.
    regards
    Jorge A.

  • How to use session object in windows application

    hi, I am programming in jdeveloper. i need to know that while i m making a web application i can use a session object for the particular session. now i m builiding a windows application for my final semester and i need to insert product id and then it should go to another frame and there it can store multiple information for a particular product id.
    e.g
    product id : 001
    next frame.
    filter name.
    filter position.
    when these are added then it should be able to add more filters for the same product id and i dont understand how to do that.
    Please let me know as i am lost and dont know how to proceed further. if some body wants to have a look on the codes he is most welcome.
    Waiting for an answer
    thank you

    Hi,
    in Swing applications you don't have a session object to store data. You can use a helper class though to act as a temporary memory. Just create a static class that has a hashtable method to add / read / remove data
    Frank

  • How to use own created WebService in BPEL?

    Hello!
    I have a problem using an own created Web Service (a wsdl file) in BPEL Process Manager.
    At the moment I have a Java program which is getting values from SAP via SAPJConnector. From this Java program I generate an WebService File (wsdl) via Axis (on my local Tomcat Server).
    Now I want to use this own created WebService (wsdl file) in BPEL. I don't know how to bulid it to my BPEL Server so that I can use it in JDeveloper.
    Does anyone know what I have to do?
    Would be nice if someone could help me, because its very important
    Thank you

    Hi.
    Thanks for your reply.
    The way to invoke the WebService in BPEL Designer is not the problem i have.
    The problem i have is how to deploy my own created WebService (from a Java class with AXIS) to the BPEL server (OC4J).
    Do you know a solution for this?
    I described my Problem detailed in another thread "Thread: Issues Publishing Web Service to OJ4J"
    Tanks and Regards
    Benjamin

  • How to use session messages ?

    Hi Friends,
    As we know , when any auth error during login , we setup message
    Like " INVALID LOGIN" or "AUTH FAIL" but this message remains until
    we login another time.
    If is there any way, when message is displayed and if we refresh message
    is removed out. ( just like we use it on cakePHP ). called Flash messages.
    How do I achieve in java / jsp ??
    Any Help appreciated....

    Then, like I said, put that message into the request scope instead. That way, on a new request (like a refresh or reload), that message will not be available, it will only ever be displayed once.
    If you absolutely must put it into the session scope, then you can manually remove it once you're done display it so that it won't be available next time.
    It depends on what logic you're employing to display this message but I think the above suggestions should do what you need.
    People on the forum help others voluntarily, it's not their job.
    Help them help you.
    Learn how to ask questions first: http://www.catb.org/~esr/faqs/smart-questions.html
    ----------------------------------------------------------------

  • How to use Session Key-based Request Targeting Mechanism in OCCAS ??

    I read Session Key-Based Request Targeting(chapter 5) in Developing SIP Applications.
    But, I don't work my application using this mechanism.
    I add sesssionKey function with @SipApplicationKey annotation.
    I deploy this application. And then, other machine send INVITE request.
    My application received INVITE request. But sessionKey function is not called before doInvite function is called.
    I used @SipApplicationKey(applicationName="...") annotation.
    It didn't work.
    sample code is following.
    Could someone help me?
    import javax.servlet.ServletConfig;
    import javax.servlet.ServletContext;
    import javax.servlet.ServletException;
    import javax.servlet.sip.SipFactory;
    import javax.servlet.sip.SipServlet;
    import javax.servlet.sip.SipServletMessage;
    import javax.servlet.sip.SipServletRequest;
    import javax.servlet.sip.SipServletResponse;
    import javax.servlet.sip.SipURI;
    import javax.servlet.sip.URI;
    import javax.servlet.sip.annotation.SipApplicationKey;
    public class app2SipServlet extends SipServlet {
    private static final long serialVersionUID = 1L;
    public static SipFactory sipFactory;
    public static ServletContext sc;
    public void init(ServletConfig cfg) throws ServletException {
    super.init(cfg);
    sipFactory = getSipFactory();
    sc = getServletContext();
    trace("+++ app2SipServlet Initialization");          
    @SipApplicationKey
    public static String sessionKey(SipServletRequest req) {
    String appid = req.getHeader("ApplicationID");
    System.out.println("application id : " + appid);
    return appid;
    @Override
    public void doRequest(SipServletRequest req)     throws ServletException, IOException {
    trace(req, "doRequest()");
    super.doRequest(req);
    @Override
    protected void doInvite(SipServletRequest req) throws ServletException, IOException {
    URI from = req.getFrom().getURI();
    String user = ((SipURI)from).getUser();
    trace(user + " : " + req.getSession().getApplicationSession().getId());
    trace(user + " : " + req.getSession().getApplicationSession().getApplicationName());
    SipServletResponse resp = req.createResponse(200);
    resp.send();
    trace(resp);
    }

    How many servlets you have defined in your sip.xml .If there are multiple you may want to check if
    -- You have defined main-servlet ?
    -- or Is deployment descriptor version 1.0 or 1.1

  • How to use Session ID info to send sequent requests to Https Server ?

    Hey , Gurus!
    Another problem for your talents :
    By using InputStream , I gain all info sent back from the Https server . And Session ID info is included , such as
    Session ID: {130, 17, 0, 0, 130, 170, 25, 235, 97, 13, 66, 95, 24, 241, 214, 8, 121, 216, 121, 64, 168, 15, 69, 65, 191, 192, 216, 68, 247, 130, 9, 164}
    How do I use this info in my Java Application to send next request to the Https Server ?
    Should I change the above Session ID info into another format ?
    Should I include the converted info in the Request Header or the Body ?
    Would you please give me an example ?
    Thanks a lot ...
    Have a nice day !

    Hi,
    You have to catpture the "set-cookie" header from the response which you got in the first request. The same "set-cookie" value has to be set in the subsequent requests' header. Please see the below code snippet to collect the "set-cookie" and set the cookie in the subsequest requests.
    //how to Collect the "set-cookie" from the response
    if (urlConnection != null)
    for (int i = 1;(key = urlConnection.getHeaderFieldKey(i)) != null; i++)
    System.out.println(urlConnection1.getHeaderFieldKey(i) + ": " + urlConnection.getHeaderField(key));
    if (key.equalsIgnoreCase("set-cookie"))
    String cookiValue = urlConnection1.getHeaderField(key);
    //How to set the cookie value in the subsequent requests
    urlConnection2.setRequestProperty("Cookie", cookiValue);
    Good luck.

Maybe you are looking for

  • Main view window locked on 'one pic at a time'???

    My main view window ... somehow I locked it into displaying only one-pic-at-a-time. Can't seem to get back to the library mode, or whatever it might be called, when I can see all the pics in the folder at the same time. I can't for the life of me fig

  • Unable to open pdf

    unable to open the pdf error An unrecognized token 'BT70.85' was found. DATA: i_p0000 TYPE TABLE OF p0000 WITH HEADER LINE,       "ITab P0000         i_p0001 TYPE TABLE OF p0001 WITH HEADER LINE.       "ITab P0001   DATA : tline LIKE tline OCCURS 0 W

  • User exit or other enhancements to change the status of the kanban.

    The requested to trigger the movement when the kanban status changed from empty to full. if itu2019s possible to use user exit or other enhancements to change the status of the kanban. can you please guide me iam new for enhancements.

  • Compile time constants

    Hey i have a doubt regd compile time constants byte a =10,b=20; byte c= a+b; // compile time error coz a+b may exceed byte limit int a=10,b=20; int d=a+b; // not showing any error . a+b may exceed int limit can anyone clear me int his

  • Ergent Help Using JBoss, EJBs ...

    Hey to all .... Please help me, i just started EJBs and i am having difficulties with the given project. So .. I am using EJB, Jboss too deploy everything I have created my entities and some sessions. Entities have created my database correctly. Now