How to set a session in Java Filter?

I make a filter,in this filter,I check a request parameter,if this parameter equals a assigned name,I put a flag into a session,like follows:
public void doFilter(ServletRequest request,ServletResponse response,FilterChain chain) throws IOException,ServletException
String name=request.getParameter("name");
if(name.compareTo("John")==0){
session.setAttribute("isLogin","true");
But when I run above program,I will get a error,because session is not defined. I know HttpSession is get by HttpServletRequest.getSession(),
but public void doFilter is only provide ServletRequest,not HttpServletRequest! I want to know whether there is a method which I can get HttpSession in Filter?
Any idea will be appreciated!

Hi. You should be able to simply cast The ServletRequest like this:
(HttpServletRequest)request
If you run a webcontainer, you're pretty sure its a Http-request.

Similar Messages

  • How to set proxy authentication using java properties at run time

    Hi All,
    How to set proxy authentication using java properties on the command line, or in Netbeans (Project => Properties
    => Run => Arguments). Below is a simple URL data extract program which works in absence of firewall:
    import java.io.*;
    import java.net.*;
    public class DnldURLWithoutUsingProxy {
       public static void main (String[] args) {
          URL u;
          InputStream is = null;
          DataInputStream dis;
          String s;
          try {
              u = new URL("http://www.yahoo.com.au/index.html");
             is = u.openStream();         // throws an IOException
             dis = new DataInputStream(new BufferedInputStream(is));
             BufferedReader br = new BufferedReader(new InputStreamReader(dis));
          String strLine;
          //Read File Line By Line
          while ((strLine = br.readLine()) != null)      {
          // Print the content on the console
              System.out.println (strLine);
          //Close the input stream
          dis.close();
          } catch (MalformedURLException mue) {
             System.out.println("Ouch - a MalformedURLException happened.");
             mue.printStackTrace();
             System.exit(1);
          } catch (IOException ioe) {
             System.out.println("Oops- an IOException happened.");
             ioe.printStackTrace();
             System.exit(1);
          } finally {
             try {
                is.close();
             } catch (IOException ioe) {
    }However, it generated the following message when run behind the firewall:
    cd C:\Documents and Settings\abc\DnldURL\build\classes
    java -cp . DnldURLWithoutUsingProxy
    Oops- an IOException happened.
    java.net.ConnectException: Connection refused
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:305)
    at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:171)
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:158)
    at java.net.Socket.connect(Socket.java:452)
    at java.net.Socket.connect(Socket.java:402)
    at sun.net.NetworkClient.doConnect(NetworkClient.java:139)
    at sun.net.www.http.HttpClient.openServer(HttpClient.java:402)
    at sun.net.www.http.HttpClient.openServer(HttpClient.java:618)
    at sun.net.www.http.HttpClient.<init>(HttpClient.java:306)
    at sun.net.www.http.HttpClient.<init>(HttpClient.java:267)
    at sun.net.www.http.HttpClient.New(HttpClient.java:339)
    at sun.net.www.http.HttpClient.New(HttpClient.java:320)
    at sun.net.www.http.HttpClient.New(HttpClient.java:315)
    at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:510)
    at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:487)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:615) at java.net.URL.openStream(URL.java:913) at DnldURLWithoutUsingProxy.main(DnldURLWithoutUsingProxy.java:17)
    I have also tried the command without much luck either:
    java -cp . -Dhttp.proxyHost=wwwproxy -Dhttp.proxyPort=80 DnldURLWithoutUsingProxy
    Oops- an IOException happened.
    java.io.IOException: Server returned HTTP response code: 407 for URL: http://www.yahoo.com.au/index.html
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1245) at java.net.URL.openStream(URL.java:1009) at DnldURLWithoutUsingProxy.main(DnldURLWithoutUsingProxy.java:17)
    All outgoing traffic needs to use the proxy wwwproxy (alias to http://proxypac/proxy.pac) on port 80, where it will prompt for valid authentication before allowing to get through.
    There is no problem pinging www.yahoo.com from this system.
    I am running jdk1.6.0_03, Netbeans 6.0 on Windows XP platform.
    I have tried Greg Sporar's Blog on setting the JVM option in Sun Java System Application Server (GlassFish) and
    Java Control Panel - Use browser settings without success.
    Thanks,
    George

    Hi All,
    How to set proxy authentication using java properties on the command line, or in Netbeans (Project => Properties
    => Run => Arguments). Below is a simple URL data extract program which works in absence of firewall:
    import java.io.*;
    import java.net.*;
    public class DnldURLWithoutUsingProxy {
       public static void main (String[] args) {
          URL u;
          InputStream is = null;
          DataInputStream dis;
          String s;
          try {
              u = new URL("http://www.yahoo.com.au/index.html");
             is = u.openStream();         // throws an IOException
             dis = new DataInputStream(new BufferedInputStream(is));
             BufferedReader br = new BufferedReader(new InputStreamReader(dis));
          String strLine;
          //Read File Line By Line
          while ((strLine = br.readLine()) != null)      {
          // Print the content on the console
              System.out.println (strLine);
          //Close the input stream
          dis.close();
          } catch (MalformedURLException mue) {
             System.out.println("Ouch - a MalformedURLException happened.");
             mue.printStackTrace();
             System.exit(1);
          } catch (IOException ioe) {
             System.out.println("Oops- an IOException happened.");
             ioe.printStackTrace();
             System.exit(1);
          } finally {
             try {
                is.close();
             } catch (IOException ioe) {
    }However, it generated the following message when run behind the firewall:
    cd C:\Documents and Settings\abc\DnldURL\build\classes
    java -cp . DnldURLWithoutUsingProxy
    Oops- an IOException happened.
    java.net.ConnectException: Connection refused
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:305)
    at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:171)
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:158)
    at java.net.Socket.connect(Socket.java:452)
    at java.net.Socket.connect(Socket.java:402)
    at sun.net.NetworkClient.doConnect(NetworkClient.java:139)
    at sun.net.www.http.HttpClient.openServer(HttpClient.java:402)
    at sun.net.www.http.HttpClient.openServer(HttpClient.java:618)
    at sun.net.www.http.HttpClient.<init>(HttpClient.java:306)
    at sun.net.www.http.HttpClient.<init>(HttpClient.java:267)
    at sun.net.www.http.HttpClient.New(HttpClient.java:339)
    at sun.net.www.http.HttpClient.New(HttpClient.java:320)
    at sun.net.www.http.HttpClient.New(HttpClient.java:315)
    at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:510)
    at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:487)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:615) at java.net.URL.openStream(URL.java:913) at DnldURLWithoutUsingProxy.main(DnldURLWithoutUsingProxy.java:17)
    I have also tried the command without much luck either:
    java -cp . -Dhttp.proxyHost=wwwproxy -Dhttp.proxyPort=80 DnldURLWithoutUsingProxy
    Oops- an IOException happened.
    java.io.IOException: Server returned HTTP response code: 407 for URL: http://www.yahoo.com.au/index.html
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1245) at java.net.URL.openStream(URL.java:1009) at DnldURLWithoutUsingProxy.main(DnldURLWithoutUsingProxy.java:17)
    All outgoing traffic needs to use the proxy wwwproxy (alias to http://proxypac/proxy.pac) on port 80, where it will prompt for valid authentication before allowing to get through.
    There is no problem pinging www.yahoo.com from this system.
    I am running jdk1.6.0_03, Netbeans 6.0 on Windows XP platform.
    I have tried Greg Sporar's Blog on setting the JVM option in Sun Java System Application Server (GlassFish) and
    Java Control Panel - Use browser settings without success.
    Thanks,
    George

  • How to set enviroment variables for Inso Filter

    Hi everyone,
    I want to convert word documents to html using CTX_DOC.Filter.According to the documentation,I know I neednot set the 'Inso Filter'in the preference when creating index,but I must set enviroment variables for Inso Filter.
    I found the following instructions for it in the 8.1.5 documentation,but I can't understand it well.Is there anyone can tell me how to set enviroments variables for Inso Filter on Windows2000 Server?(My DB version is 8.1.7EE)
    Environment Variable Locations
    All environment variables related to Inso filtering must made visible to interMedia Text. Set these variables in the following locations:
    listener.ora file. This makes the environment variables visible to the extproc PL/SQL process.
    The operating system shell from where ctxsrv server is started. This makes the environment variables visible to the ctxsrv process, which does background DML.
    Any suggestions are apreciated
    Reemon
    null

    NSAPI plugins are normally configured using parameters specified in magnus.conf and/or obj.conf. What plugin requires you set an environment variable?

  • How to set a session variable

    Hi,
    I would like to know how to set a session variable for the following purpose.
    At the top of my application I have a "Welcome <username>" I'd like it instead to have "Welcome <firstname> <lastname>".
    So the concept would be after the user logs in succesfully this session variable is dynamically set so it can be displayed.

    Hi Scott,
    I realize that I can set items etc in pages. The case I'm referring to is a reference in a template. My template has a "Welcome <user name>" ... so the code looks like "Welcome &APP_USER." Anyway to make it say "Welcome first_name last_name" in the template? Note I'll have to get the first/last names from a query
    Thanks,
    Marty

  • How to set iframe src from java dynammically

    Hi,
    Iam calling a servlet from jsp and servlet calls the databse query and returns the value,
    in my jsp i have ifrme, i want to change the source of iframe from java depends on the result from database , and the result must display on the iframe can any one tell me how to do this

    aurelian_cl wrote:
    I need to know how to set environment variables from java
    I want to set from java for example the environment variable "TestVar" with the value "TestValue"!1) That functionality does not belong in an application. You're trying to set environment variables, which are global across all applications, at either the user level as a whole, or across the entire machine (system level). Or, if you're only trying to set a variable active for the current process, you don't need to do that.
    2) Environment variables are not a platform-independent entity, and are thus against the nature of Java.
    My gut feel is that you are designing something in a backwards way, so my point is mainly to point that out, not to try to help you solve that particular problem.

  • How to set the session using onClick event?

    Dear All,
    I have a link, which once the user click on it, I want to set the session.
    <a href="link.jsp" > Link </a>How to set the session? Where should I put <%session1.setAttribute ("test", "1234"); %>?
    Any idea?
    Thanks

    when u click on Link
    the control goes to link.jsp/.
    and in this page u can write the session related code.

  • How to set variable to run java and j2ee

    how to set variable to run java and j2ee

    Please ask a specific and comprehensible question. Consider describing with less vagueness the actual current problem that you are encountering.

  • How to set portal context using Java/JPDK api.

    Hi,
    I am in the process of converting pl/sql based database provider contect portlets to Java based JPDK. I ran into issue where the database provider portlet users were getting context auto matically. Now with Java/JPDK portlets , I am receiving no data found error, since the context is not set. The pl/sql is setting wwctx_private_api.set_context ('portal') to set the context. From Java if we call this api, it is taking a toll on the performance and the portlet times out.
    Can any help how to set the context for a web provider using JPDK or any other better solution. Any immediate help is highly appreciated.
    Thanks,
    Rav.

    Hi
    We are trying to access content views for e.g portal.wwsbr_all_items s, portal.wwsbr_all_content_areas c,portal.wwsbr_all_folders f, from aweb provider portlet. When we do a select on those objects , we are getting java sql exception saying "ORA-06510: PL/SQL: unhandled user-defined exception
    ORA-06512: at "PORTAL.WWCTX_SSO", line 1745
    ORA-06510: PL/SQL: unhandled user-defined exception
    ORA-06512: at "PORTAL.WWCTX_SSO", line 1579
    ORA-06502: PL/SQL: numeric or value error
    ORA-06512: at "PORTAL.WWCTX_SSO", line 1834
    ORA-06512: at "PORTAL.WWCTX_API", line 199
    We need to know how to accesss the above views from a jsp based portlet.
    A

  • How to set FOCUS on applet (java-plugin)

    I wrote applet using Java 1.3.1, using swing clasess.
    I use java-plugin, defined in <object ..> and <embed ..> tags as described in documentation,
    with MAYSCRIPT parameter and ID and NAME parameters defined.
    How to set up focus on this applet through JavaScript?
    I have tried:
    document.embeds[0].focus()
    document.applets.MyApplet.focus()
    document.objects.MyApplet.focus()
    document.objects[0].focus()
    document.MyApplet.focus()
    But nothing works in my IE5.x or NC4.7. Applet itself works fine.
    Is some special methods need to be defined in JApplet to catch the focus?
    Thanks for any advice.

    I wrote applet using Java 1.3.1, using swing clasess.
    I use java-plugin, defined in <object ..> and <embed
    ..> tags as described in documentation,
    with MAYSCRIPT parameter and ID and NAME parameters
    defined.
    How to set up focus on this applet through
    JavaScript?
    I have tried:
    document.embeds[0].focus()
    document.applets.MyApplet.focus()
    document.objects.MyApplet.focus()
    document.objects[0].focus()
    document.MyApplet.focus()
    But nothing works in my IE5.x or NC4.7. Applet itself
    works fine.
    Is some special methods need to be defined in JApplet
    to catch the focus?
    Thanks for any advice.With IE you should try the following:
    <OBJECT id='MyApplet' ...
    document.MyApplet.requestFocus();
    This worked fine for me, even without specifying additional "MAYSCRIPT" or "scriptable=true" tags. Obviously this construct managed to call the public Java method "requestFocus()" from JavaScript.
    Maybe something similar would also work for Netscape. I felt no need to do this when running in Netscape, because the Netscape browser handled focus management without problems.
    For IE I tried to workaround a problem mentioned by several people in this forum: The focus will not be regained by an applet when the user switched form IE to another application and then returns back to the browser window which contains the applet.
    Unfortunally the following code fragment worked only partially well:
    function activated()
    if (isIE)
    document.MyApplet.requestFocus();
    return true;
    window.onfocus = activated();
    OnFocus is invoked only each second time when the browser window gains back focus.
    I'm still looking for a real solution, so I'd appreciate if anybody could come up with one.
    Hope this helps a bit
    Bernd

  • How to set environment variables using java program

    Hi all
    I want to set environment variables on windows 98/200/xp system, such as path and classpath using a java program.
    How to do this using a java program.
    Any body plz helppppppppp.

    #1 05-02-2003, 07:38 AM
    Goodz13 Join Date: Jan 2002, Posts: 985
    Location: Halifax, NS, Canada
    Reputation:
    Java FAQ's and tutorials
    Java FAQ's
    Path and ClassPath:
    PATH
    In Windows 9x you would set it up in the autoexec.bat file
    ie.
    SET PATH=%PATH%;c:\jdk1.4.2\bin\;
    where c:\jdk1.4.2\ is the path where you installed Java.
    In Windows 2000 and XP
    Right click on My Computer->Properties->Advanced Tab->Environment Variables... Button.
    If you see a PATH in System Variables, click that and edit it. If you don't, you will need to create a new System variable.
    It should look something like this:
    %SystemRoot%\system32;%SystemRoot%;c:\jdk1.4.2\bin\;
    Any querry email me to [email protected]
    Answer by
    Rajasekhar Goli
    DS UNICS Infotech

  • How to set applet  parameter in java code?

    Hi All,
    Instead of setting applet parameters in JSP page, Now I have a need to set
    applet parameters in java code. But I can't find a method that allow me to do this. There
    is only getParameter but seems no setParameter method.
    Any help is appreaciated.
    Thanks,
    Chris

    Take a look at set_custom_property:
    public static final ID SETTEXT = ID.registerProperty("SETTEXT");
    public boolean setProperty(ID pid, Object value)
        if (pid == SETTEXT)
    String text = value.toString();
    and in forms
    set_custom_property('beans.bean_item', 1, 'SETTEXT', 'some text');
    cheers

  • How to set database session info

    Jdev 9.0.3.3
    My app manages user logins via a custom jaas implementation, but it connects to the db using a shared username/password. I capture the real username password of the logged in user in my app and want to add that info to some audit columns on my tables like Created_By, Updated_By, etc.
    How do I pass in a value stored in my Java code to the db session so I can use that data in a trigger or whatever.
    I understand there is a way to access the db session from the app mod, but I am unclear on how to do this.
    TIA

    Jdev 9.0.3.3
    My app manages user logins via a custom jaas implementation, but it connects to the db using a shared username/password. I capture the real username password of the logged in user in my app and want to add that info to some audit columns on my tables like Created_By, Updated_By, etc.
    How do I pass in a value stored in my Java code to the db session so I can use that data in a trigger or whatever.
    I understand there is a way to access the db session from the app mod, but I am unclear on how to do this.
    TIA

  • How to set properties in XCM java appllication in NWDS

    Hi,
    Its Java Application using NWDS
    I need to set the properties which can be changed or controlled easily in different servers. I heard XCM is used for this purpose.
    I need guidance which config files will be used in XCM folder and how to use them in Java application.
    Eg. I need to set email host and port property and its value will keep changing on different severs.
    Where should I set it and how to access it.??
    Thanks

    hi
    check this
    http://help.sap.com/bp_bblibrary/600/Documentation/C20_BB_ConfigGuide_EN_GCC.doc
    http://www.freebooksclub.net/sap/2011-sap-srm-extended-classic-cookbook-0975305271.html
    bvr
    Edited by: bvr on Mar 12, 2009 10:19 AM

  • How to set v$session.program ?

    Hi,
    I would like to set the v$session.program value to audit this after logon.
    In sqlplus I can see some program entries : plsqldev.exe, sqlplusw.exe, oem etc
    but I can not find the program entry for Forms & Reports 6i.
    How can I set this v$session.program value ?
    Many thanks and regards,
    Friedhold

    You cannot set the program; it is automatically filled with the OS executable that has created the session.
    If I enter Forms Builder and connect, then I see "ifbld90.exe" in the program column.
    Regards,
    Rob.
    Edited by: Rob van Wijk on 28-aug-2009 13:05
    Note that I was unaware of the information in Mohan Nair's referred thread.
    Here is a nice article: http://www.integrigy.com/security-resources/analysis/Integrigy_Spoofing_Oracle_Session_Information.pdf
    Quote: +"The program name is supplied directly by the client and can be set to any value by an attacker. The program value is set during the session initialization. Using the Oracle JDBC driver, the value can be set prior to the connection initialization. With the Oracle OCI driver, simply renaming the “exe” file will allow you to manipulate the program name."+

  • How to set a variable in JAVA ?

    I am using following code to load a file
    properties.load(Thread.currentThread().getContextClassLoader().getResourceAsStream("FILENAME"))
    This works fine but I dont want to hardcode the filename, instead I want to use a menthod which rerutns me the file name to be supplied here.
    How can I set this in two steps ?
    That is if methodA returns the filename then
    I want to do something like unix export
    FILENAME=xxxxxxx
    & then use FILENAME in quotes in above code so that the value is passed on.
    Please help me to do this.
    Thanks

    How can I set this in two steps ?
    That is if methodA returns the filename then
    I want to do something like unix export
    FILENAME=xxxxxxx
    & then use FILENAME in quotes in above code so that
    the value is passed on.
    Please help me to do this.You probably need at least three seperate objects. One to create references based on supplied requirements, one to manage the loading which uses the first and then perhaps a third which provides the saving and retrieving of the references. This is if you plan to scale-up the application. If you don't want to use environment variables you could also look at using serialisation.

Maybe you are looking for

  • MY IPOD TOUCH IS DISABLED, CONNECT TO ITUNE?

    My iPod Touch is disabled. Its says connect to iTune, and did. But it dosent work. The massage shows your iPod touch in LOCKED by passcode. You must unock before you used iTune. But my ipod is disabled how do i enter the password. Pleace HELP!!! me.

  • Usage tax calculation

    Hi, In US tax is calculated in 2 ways as sales tax or Use tax.For registered vendors Sales tax will be paid along with invoice but unregistered vendors use tax will be calculated which will be paid to Govt directly. I am able to configure sales tax b

  • Sonnett Aria not seeing Airport in Lombard G3

    Friends, I have a Power book G3 Lombard bronze keyboard. 333Mhz 512 mg memory. OS 10.4.9 using AIR PORT 4.2 utility. I purchased a Aria extreme Sonnett. for wireless internet. The MAC sees the card but will not see the airport. The card icon is in th

  • Printing on Zebra printer

    Hi We are using zebra printer model TLP3844-z. We are facing following problem. When we are printing only labels it is printing through SAP but as soo as we add image to that label it is not printing through SAP. But at the same time from zebra label

  • Hide workitems in SBWP or raise error when execute in SBWP

    Actually I want to make sure that workitems of some tasks should be executed in UWL only. At the moment they appear in both inboxes. I had 2 different solutions in focus 1) Raise an error message when executed in GUI inbox (SBWP) or 2) hide those ite