Session id in response

Dear All,
Is that a possible way to set the sessionid in the response so that I can do a redirect with the sessionid in the response?
I have tried the following code, but it's not working,
response.setHeader("cookie", "JSESSIONID="+sessionId);
response.sendRedirect(url);
Thanks in advance.
ar_fee

Hi, I think you will get a sessionId in response and all you can do is get that session id from the cookie and append the same sessionid in your url as ;jsessionid=sessionid.
what i did in my application was i got sessionid from the response and used same sessionid in another url.

Similar Messages

  • Cannot create a session after the response has been committed (Tomcat 6)

    I'm getting a rather annoying error when I try to open a pretty basic JSP page.
    I'm rather new to the whole JSP scene, so I'm following the example found on pages 287 and onwards in "JSF in Action - Manning" in case anyone wanted to check my code against the source.
    I've searched for about 4 hours now, coming back to this site a couple of times, once reading about writeouts and stuff. But I'm not really sure this is the issue in this case and if it is, where exactly the problem lies.
    I've already fixed a number of errors I got (jtsl.jar and standard.jar missing etc...) but this particular problem is driving me (and my co-workers for that matter :-) ) up the wall.
    Anyone willing to help me out here?
    Error:
    description The server encountered an internal error () that prevented it from fulfilling this request.
    exception
    javax.servlet.ServletException: Cannot create a session after the response has been committed
         javax.faces.webapp.FacesServlet.service(FacesServlet.java:152)
    root cause
    java.lang.IllegalStateException: Cannot create a session after the response has been committed
         org.apache.catalina.connector.Request.doGetSession(Request.java:2301)
         org.apache.catalina.connector.Request.getSession(Request.java:2075)
         org.apache.catalina.connector.RequestFacade.getSession(RequestFacade.java:833)
         org.apache.myfaces.context.servlet.SessionMap.setAttribute(SessionMap.java:53)
         org.apache.myfaces.util.AbstractAttributeMap.put(AbstractAttributeMap.java:103)
         org.apache.myfaces.util.AbstractAttributeMap.put(AbstractAttributeMap.java:35)
         org.apache.myfaces.application.jsp.JspStateManagerImpl.saveSerializedViewInServletSession(JspStateManagerImpl.java:523)
         org.apache.myfaces.application.jsp.JspStateManagerImpl.saveSerializedView(JspStateManagerImpl.java:358)
         javax.faces.application.StateManager.saveView(StateManager.java:47)
         org.apache.myfaces.application.jsp.JspViewHandlerImpl$StateMarkerAwareWriter.flushToWriter(JspViewHandlerImpl.java:387)
         org.apache.myfaces.application.jsp.JspViewHandlerImpl.renderView(JspViewHandlerImpl.java:322)
         org.apache.myfaces.lifecycle.RenderResponseExecutor.execute(RenderResponseExecutor.java:41)
         org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:132)
         javax.faces.webapp.FacesServlet.service(FacesServlet.java:138)
    Source Code of login.jsp:
    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
        pageEncoding="ISO-8859-1"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
    <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
    <f:view>
    <html>
    <head>
         <title>
              <h:outputText value="ProjectTrack"/>
         </title>
    </head>
         <body>
              <table>
                   <tr>
                        <td>
                             <h:graphicImage url="/images/logo Skillteam.jpg"
                             alt="Welcome to ProjectTrack"
                             title="Welcome to ProjectTrack"
                             width="435" height="120"/>
                        </td>
                   <td>
                        <font face="Arial, sans-serif"
                        size="6">
                        <h:outputText value="ProjectTrack"/>
                        </font>
                   </td>
                   </tr>
         http://forum.java.sun.com/post!default.jspa?forumID=45#
    Click for bold     </table>
         </body>
    </html>
    </f:view>
    web.xml & faces-config
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
         <display-name>ProjectTrack</display-name>
         <welcome-file-list>
         <welcome-file>faces/login.jsp</welcome-file>
         <welcome-file>index.html</welcome-file>
         </welcome-file-list>
         <servlet>
         <servlet-name>Faces Servlet</servlet-name>
         <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
         <load-on-startup>1</load-on-startup>
         </servlet>
         <servlet-mapping>
         <servlet-name>Faces Servlet</servlet-name>
         <url-pattern>/faces/*</url-pattern>
         </servlet-mapping>
    </web-app>
    <?xml version="1.0"?>
    <!DOCTYPE faces-config PUBLIC
    "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.0//EN"
    "http://java.sun.com/dtd/web-facesconfig_1_0.dtd">
    <faces-config>
         <navigation-rule>
              <from-view-id>/login.jsp</from-view-id>
              <navigation-case>
                   <from-outcome>success</from-outcome>
                   <to-view-id>/inbox.jsp</to-view-id>
              </navigation-case>
              <navigation-case>
                   <from-outcome>failure</from-outcome>
                   <to-view-id>/login.jsp</to-view-id>
              </navigation-case>
         </navigation-rule>
    </faces-config>Setup:
    Eclipse Europe 3.3.0
    Tomcat 6.0.13
    MyFaces 1.2
    JRE 1.6.0_02

    When searching for this error, this was the first page google gave me. I found the answer and just in case anyone else stumbles in here with the same question I thought I'd share my findings.
    Unfortunately, if your problem is the same as mine, you're going to feel pretty silly. I was navigating to the wrong page. If MyFaces(when running tomcat) tries to resolve to a page that doesn't exist, the error given above is what happens.
    In my case I accidentally put my .jsp page into the wrong directory and ended up banging my head against the wall for an hour figuring that out. Hope this helps someone.

  • Error: WEB3010: Cannot create a session after the response has been committ

    Hi,
    I am seeking more information on that error. You know how to explain to me what she is, which the possible causes, if somebody already had some problem where that mistake happened.
    Please, if somebody has some information he send me.
    Thanks
    Denis

    Committing a response involves sending headers/data back to the client. When a web application session is created, the session ID needs to be sent back to the client. This is done either via a Set-Cookie header or is encoded in the URLs returned to the client. When response has been committed before the session is created, there is no way for the session ID to be sent back to the client, hence the error.
    To correct the error, either increase the size of the output buffer or page buffer (if it is a JSP) or remove any calls that may be flushing data (thereby committing the response) to the client.

  • Sap-syscmd=nocookie and Statefull BSP's - Session timeout

    I have a tricky problem - and I'am hoping for your helpfull input... please..
    I have developed a Statefull BSP application - and this application should be called from a SAP CRM application - and it should be possible to call and execute this aplication in a new session everytime it's called from CRM (a new controller/model instance per call).
    In the CRM application I can define the JavaScript which should be exectued in order to start the external application - and I have used the script window.open('bsp-url) to start my BSP application.
    In my first attempt I ran into the problem that all new windows was started in the same new session - with the consequence that all new windows tried to use the same controller and model instance - leading to inconsistent data...
    Then I read an SDN article about the parameter sap-syscmd=nocookie. With this url parameter it should be possible to force the BSP to be executed in a new session - and it works.... or... a new session is generated and the BSP generates the correct output after the initial call  (and according to SM04 I have a new session). I was quite happy until I pressed a button in my BSP page triggering an HTMLB-event - which lead to the following error: "400 Session timed out - please login again". So it looks like the 1. part is okay with the new session - but the response generated and sent to the browser cannot frind it's way bay to the right session in SAP... what did I do wrong???

    I have already tried with sap-sessioncmd=open - and the first time the call is made from CRM a new sesion is created and the BSP is intialized. But if I go back to the CRM application again (without closing the BSP window) and hits the button again - then a new window is created but no new session meaning that the underlying BSP is referenced in both windows - and producing wrong results (they both refer to the same instance of the BSP). When I use sap-syscmd=nocookie - I get a new window and a new session everytime I hit the button in CRM, but for some reason the page-output generated cannot find it's way back to this session afterwards...

  • Invalidating the ADF session and redirecting to EBS login screen

    Hi ADF team,
    I am developing an application which is being accessed from eBusiness Suite (EBS), using ADFX function. It has a global Logout link. When the link is clicked, two things should happen.
    1. the ADF session that is running on WLS server should be killed.
    2. I should be redirected to eBusiness Suite login page.
    This is what I am doing and I am getting error(s).
    1. Created a Container jspx page and embedded a task flow in it.
    2. Embedded a jsff into task flow.
    3. In JSFF created a global link called Logout.
    4. Set the action property of Logout link such that it calls a function in the AMImpl. (I confirmed, the function is being called)
    5. In the function invalidate the ADF session using following code.
    HttpServletResponse response = ((HttpServletResponse)ADFContext.getCurrent().getEnvironment().getResponse());
    HttpServletRequest request = ((HttpServletRequest)ADFContext.getCurrent().getEnvironment().getRequest());
    HttpSession sessionADF = request.getSession();
    sessionADF.invalidate();
    return "EBSLogin";
    6. Now, EBSLogin control flow leads to a URL View component that has the URL property set as "www.oracle.com".
    --Using this approach I get the error: adfc-14000: view port id ****** is invalid
    -----Thus need help with this error. Is there a better way to accomplish this ?? What am i doing wrong?
    Also, I have a question on how to set the URL property of 'URL View' component. I set it to #{pageFlowScope.MainPageBean.testLogoutURL}. testLogoutURL is a function that returns string. But I do get an error at run time, mentioning that the property cannot be NULL. Thus seems like the way I am doing it is not totally correct. Please advice.
    Thanks & Regards,
    Anoop

    on top of my head
            FacesContext fc = FacesContext.getCurrentInstance();
            ExternalContext ectx = FacesContext.getCurrentInstance().getExternalContext();
            HttpServletResponse response = (HttpServletResponse)ectx.getResponse();
            HttpSession session = (HttpSession)ectx.getSession(false);
            String redirectURL = (String)session.getAttribute("ebizRedirectUrl");
            if(redirectURL!=null){
              int oa_html = redirectURL.indexOf("OA_HTML");
              finalRedirectURL = redirectURL.substring(0, oa_html);
              finalRedirectURL = finalRedirectURL + "oa_servlets/AppsLogin";
            if (session != null)
            session.invalidate();
            try {
                response.sendRedirect(finalRedirectURL);
                fc.responseComplete();
            } catch (IOException e) {
                e.printStackTrace();
            }

  • Custom page session not working

    Hi All,
    I have modified custom.jsp file to customize BI launchpad, where in this page I put code to display logon form and after form submission it will go to Action.jsp to validate credentials using below code.
    // If no session already exists, logon using the specified parameters.
    if (enterpriseSession == null)
      try
      // Log on to BusinessObjects Enterprise
      enterpriseSession = CrystalEnterprise.getSessionMgr().logon(strUserName,strPassword, "XXX:6400" ,strAuthType );
      defaultLogonToken = enterpriseSession.getLogonTokenMgr().getDefaultToken();
      enterpriseSession = CrystalEnterprise.getSessionMgr().logonWithToken(defaultLogonToken);
      // Store the IEnterpriseSession object in the session.
      session.setAttribute("EnterpriseSession", enterpriseSession);
      // Create the IInfoStore object.
      IInfoStore iStore = (IInfoStore) enterpriseSession.getService("InfoStore");
      // Store the IInfoStore object in the session using the
      // helper functions.
      session.setAttribute("InfoStore", iStore);
      // Store the logon token for later use.
      session.setAttribute("token", defaultLogonToken);
      catch (SDKException e) {  sSuccessFailMsg = e.getMessage();
    This code is working fine and I am able to logon and go to home page, below is the issue I am facing can you please let me know how to solve this issue.
    Once I logon to BI launchpad, if I refresh web page it's redirecting me to logon page again and also in next tab if I use same URL it's asking to to enter logon details.
    Please lt me know how to use defaultlogon token to login without entering credentials.
    Thanks,
    Mani

    Hello All,
    I am able to resolve above issue by checking BO session in Custom.jsp. I think this  will be helpful for someone who is trying to do customization.
    IEnterpriseSession enterpriseSession =(IEnterpriseSession)session.getAttribute("EnterpriseSession");
    if (enterpriseSession != null)
    String defaultLogonToken= (String)session.getAttribute("token");
    response.sendRedirect ("/BOE/BI/logon/start.do?ivsLogonToken=" + defaultLogonToken);
    Thanks,
    Mani

  • Problem with showModalDialog whenever server sends a new session cookie

    Hi,
    In our application we display a pdf to the user in a modal dialog whenever he clicks on the view button. We use siteminder for authentication.
    Only on certain machines we sporadically get a blank modal dialog instead of the pdf. I used HttpAnalyzer to check on the HTTP requests and response. I found that whenever in case of a call to DisplayPDFServlet(see the code below to understand the calls) the siteminder does a "Set-Cookie" in the response, I get a blank modal dialog and the Response content is empty.
    I tried to match my IE setting with the machines which do not have this problem, but it has been of no use.
    The view action is handled in the code as follows:
    1. Call a struts action class which fetches the pdf and puts it in session.
    2. In the jsp to which the control is now directed to, we have an object tag wherein the value is a call to a servlet which gets the pdf from the session and writes it to the outputstream
    Object tag in the jsp:
    <object id="demo" classid="clsid:CA8A9780-280D-11CF-A24D-444553540000" width="750" height="530">
                             <param name="SRC" value="servlet/com.dcs.century21.display.util.DisplayPDFServlet?<%=System.currentTimeMillis()%>">
                        </object>
    Servlet Code
    public void doPost(
              HttpServletRequest request,
              HttpServletResponse response)
              throws ServletException, IOException
              HttpSession session = request.getSession();
              response.setHeader("Cache-Control", "no-cache"); //HTTP 1.1
              response.setHeader("Pragma", "no-cache"); //HTTP 1.0
              response.setDateHeader("Expires", 0);
              //prevents caching at the proxy server          response.setContentType("application/pdf");
              response.setHeader("Content-Type", "application/pdf");
              response.setHeader(
                   "Content-Disposition",
                   "inline;filename=somepdf.pdf");
              java.io.OutputStream outputStream = response.getOutputStream();
              if (session.getAttribute("contractDocumentByteData") instanceof byte[])
                   byte[] data =
                        (byte[]) session.getAttribute("contractDocumentByteData");
                   if (data != null)
                        response.setContentLength(data.length);
                        session.removeAttribute("contractDocumentByteData");
                        outputStream.write(data, 0, data.length);
                   outputStream.flush();
                   outputStream.close();
    Please Help!!!
    Vinay

    Hi
    I tried appending a "\n" to the end of the string, this didn't work. But, it seemed that using out.println(text) instead of out.print(text) when sending the message through the socket solved the problem.
    Thanks a lot for the tip!
    CK

  • Web Service Usage Discussion - Both for request and response.

    Hi,
    I have some discussion questions ( by the way i have done my search in the forums )
    1) How would you solve the problem of registering user from iphone application without making the user to enter a security code to prevent spam?
    ( We use graphical captchas to minimize the risk in web.. but what would you do or what are you doing to make a proper registration from iphone directly to the web server? ) I can request, user, pass,email and register the user, but i can not want him to click on the confirmation code that i've sent to his/her email.. He'll leave my application, click the link,... safari will open.. etc etc...
    2) How would you authenticate the user and send commands according to that session?
    Would you send user and pass in plaintext, like many web pages' login system..?
    And after that would you just get a session id from response and after that, would you use only that code to send new commands according to that authenticated user? like ( http://myserver.com/?cmd=message&text=hi&session_id=34524534 ) ? How would you implement, or you are implementing this in iphone application?
    3)What would you use to send commands to server? You use simple url request? ( maybe somewhat REST ) or would you send xml to the server? And how would you get the response? As an XML? as comma seperated simple mode, as JSON to parse? Or would you return property list recognized by iphone? Or.... Or?? What would you use, or what are you using? What's your idea to do it in a proper way? (I know that this can change from people to people, but at least we can see what everyone is telling.. )..
    What response type you prefer and why do you prefer it? For example, you are trying to avoid xml to stay away from parsing it without standard libraries... OR... ?
    I'll be glad if you share your ideas/experiences with us? We may learn new things/we may improve our selves/we may change the way we do these things, we may be happy together (:

    Hi MaxLeyton,
    Thank you for posting in the MSDN forum.
    >>I am trying create a webmethod in a webservice, this webmethod must to have two different headers, one for request and one for response.
    Since it is related to the Web, to help you resolve this issue as soon as possible, you could post this issue to the ASP.NET forum.
    http://forums.asp.net/28.aspx/1?WCF+ASMX+and+other+Web+Services
    Best Regards,
    Jack
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • How the hell does a person share session data between JSP page and a Servle

    1. How the hell does one share session data between a servlet and a JSP page without using a bean but rather using a normal string variable.
    2. When using session scope to access a bean the application complains about not finding the bean on the specified scope, however when I use an application scope the save the same bean, the application does find it.
    Please help!!!!!!!
    SERVLET:
    HttpSession session = request.getSession(true);
    ServletContext servletContext = session.getServletContext();
    customerID = result.getString("CustomerID");
    userName = result.getString("UserName");
    session.setAttribute("UserName",userName);
    session.setAttribute("CustomerID",customerID);
    System.out.println("Customer UserName = " + session.getAttribute("UserName"));
    response.sendRedirect("/economics/subscriptions/default.jsp");
    JSP PAGE:
    <?xml version="1.0" encoding="UTF-8"?>
    <jsp:root xmlns:jsp=http://java.sun.com/JSP/Page mlns:c="http://java.sun.com/jsp/jstl/core" xmlns:sql="http://java.sun.com/jsp/jstl/sql" version="2.0">
    <jsp:directive.page isThreadSafe="true" session="true" contentType="text/xml"/><jsp:output omit-xml-declaration="false"/><jsp:scriptlet>response.addHeader("x-xslt-nocache", "true");</jsp:scriptlet><pml>
    <page type="web" search="y">
         <pageName>Commercial Banking</pageName>
         <jsp:directive.include file="/economics/header.inc"/>
         <jsp:directive.include file="/login.inc"/>
         <jsp:directive.include file="/economics/leftMenu.inc"/>
         <!--<jsp:useBean id="UserName" type="java.lang.String" scope="session" />-->
         <content>
         <searchSum>Commercial - Main Content</searchSum>
         Value = <c:out value="${request.session.getAttribute("UserName")}"/>
         </content>
         <jsp:directive.include file="/economics/rightNav.inc"/>
         <jsp:directive.include file="/footer.inc"/>
    </page></pml></jsp:root>

    For a start, just "session" instead of "request.session" would work better. But why did you post this here and not in the JSP forum? Doesn't seem to have anything to do with Java programming.

  • V$SESSION 에서 PC CLIENT 확인하기

    제품 : ORACLE SERVER
    작성날짜 : 1998-05-06
    V$SESSION 에서 PC CLIENT 확인하기
    =================================
    PURPOSE
    다음은 V$SESSION 의 'OSUSER' Column 을 사용하여 Database 에 연결된 PC
    User 를 결정하는 Client PC를 Set up 하는 간단한 방법을 소개한다.
    단, USERNAME 은 PC User 에 의해 수정될 수 있으므로 충분히 믿을만한 방법은
    아니다.
    Explanation
    1. Client Setup
    Client PC 에서 ORACLE.INI File 을 open 하여, PC 를 식별할 Unique 한
    이름을 'USERNAME' Parameter 에 setting 한다.
    예) USERNAME = pcuser582
    SQL*Net V1 이나 V2를 통해 Server 에 Connection 하며,
    Parameter 는 SQLNET_USERNAME 이 아니라 USERNAME 으로 Setting 해야 한다.
    단, 위는 win31 16 Bit 용에 해당하는 내용이며, WIN95 32 Bit 용에서는
    Windows 로그온 user에 따라 즉 Registry 의 HKEY_USER 에 등록된 User 에
    따른다.
    2. Server 에서 User 확인하기
    DBA view V$SESSION 은 OSUSER column 에 Client User 에 대한 정보를
    갖고 있다.
    SELECT ALL SYS.V_$SESSION.OSUSER, SYS.V_$SESSION.USERNAME,
    SYS.V_$SESSION.TERMINAL, SYS.V_$SESSION.PROGRAM,
    SYS.V_$PROCESS.SPID SERVER_PID
    FROM SYS.V_$PROCESS, SYS.V_$SESSION
    WHERE SYS.V_$PROCESS.ADDR=SYS.V_$SESSION.PADDR;
    OUTPUT 예 :
    OSUSER USERNAME TERMINAL PROGRAM SERVER_PI
    rctest73 ? oracle@kr........ 8313
    rctest73 ? oracle@kr........ 1879
    rctest73 ? oracle@kr........ 8276
    rctest73 ? oracle@kr........ 8335
    rctest73 ? oracle@kr........ 5911
    esjo SCOTT Windows 95 OraPgm 2469
    changhc OEM15 CHANGHC VOD.EXE 2469
    kbpark KBPARK KBPARK F45DES32.EXE 2469
    rctest73 SCOTT ttyp1 sqlplus@kr... (TNS V1-V2) 10218
    rctest73 SCOTT ttyp1 sqlplus@kr... (TNS V1-V2) 26421
    rctest73 SYSTEM ttyqf sqlplus@kr... (TNS V1-V2) 11104
    3. Additional Views
    Oracle V7.2에서는 V$SESSION_CONNECT_INFO View 가 소개된다.
    위의 Query 와 Match 되는 OSUSER Column 이 있으며, SQL*Net Banner 를
    포함하고 있다.
    Example
    Reference Document
    ------------------

    Hi,
    Did anyone figured this out? I have exactly same problem.
    Redhat 5.3, Oracle 10.2.0.4.
    Running desc v$process, v$session_event, v$sysstat and a few others, no problem. Type "desc v$session" from a remote Linux client connection (sqlplus user/pass@dbname) hangs the session, ie no response, nothing comes back. The client is running on Windows 7 professional and there is a firewall between client and the server.
    Running the same desc on the local server, or another client (Windows 2008 machine) running on same n/w as Oracle db server i.e. no firewall runs fine.
    It only hangs on v$session and v$database. At least, those are the two I've found so far.
    Any suggestions? I already did a session trace and output is shown below:
    PARSING IN CURSOR #1 len=23 dep=1 uid=0 oct=3 lid=0 tim=1282079426155587 hv=4205271090 ad='9d2d4c80'
    SELECT * FROM V$SESSION
    END OF STMT
    PARSE #1:c=0,e=179,p=0,cr=0,cu=0,mis=0,r=0,dep=1,og=4,tim=1282079426155583
    WAIT #0: nam='SQL*Net message to client' ela= 2 driver id=1413697536 #bytes=1 p3=0 obj#=-1 tim=1282079426156226
    WAIT #0: nam='SQL*Net more data to client' ela= 38 driver id=1413697536 #bytes=2003 p3=0 obj#=-1 tim=1282079426156339
    WAIT #0: nam='SQL*Net more data to client' ela= 9 driver id=1413697536 #bytes=2001 p3=0 obj#=-1 tim=1282079426156390
    WAIT #0: nam='SQL*Net more data to client' ela= 5 driver id=1413697536 #bytes=1999 p3=0 obj#=-1 tim=1282079426156434
    WAIT #0: nam='SQL*Net more data to client' ela= 4 driver id=1413697536 #bytes=2002 p3=0 obj#=-1 tim=1282079426156476
    WAIT #0: nam='SQL*Net more data to client' ela= 5 driver id=1413697536 #bytes=2003 p3=0 obj#=-1 tim=1282079426156519
    WAIT #0: nam='SQL*Net more data to client' ela= 4 driver id=1413697536 #bytes=2001 p3=0 obj#=-1 tim=1282079426156562
    WAIT #0: nam='SQL*Net more data to client' ela= 4 driver id=1413697536 #bytes=2000 p3=0 obj#=-1 tim=1282079426156604
    Thanks,
    Paresh

  • Illegal State Exception with response.sendRedirect

    Hi all,
    When i am using response.sendRedirect(address), It is giving illegal state exception at few places. At few places it is working fine. I couldnt trace the reason.
    I am using tomcat 4.1 with SSL configured for the server. Will session tracking effect response.sendRedirect(address)'s ability any way?
    Can any body help me out...
    Thanks in advance...
    krish

    I believe this quite often occurs when you have tried to send some kind of response already. I.E. you should not have sent anything to the client when you call this method so start by looking for any write's you have prior to the sendRedirect().
    Ted.

  • Session Conflict

    Hello,
    I build a game in asp.net with vb.
    It is a simple survey. There is questions and 4 answer for each question. You can pass or 50% for once.
    Some times the game conflicts. When a user plays the game in the middle of questions it jumps to an other question or begins from start again. All the data is storing in session when the user starts to play. I think the sessions are conflicting.
    But i tried it with 5-6 person and it Works fine. But in my customer when they start to play with over 10 person they call me back with this situation. So what is wrong, please help me.
    It is very simple within a one aspx file. I send it below.
    <%@ Page Language="VB" MasterPageFile="~/MasterPage.master" %>
    <%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="Ajax" %>
    <%@ Import Namespace="Connections" %>
    <script runat="server">
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
    'Server.ScriptTimeout = 9000
    'Session.Timeout = 3600
    Dim ID As String = Request.QueryString("id")
    If ID = "" Then Response.Redirect("Oyunlar.aspx")
    If Not Page.IsPostBack Then
    Using Conn1 As New SqlConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString)
    Conn1.Open()
    Dim SQL As String = "SELECT Oyunlar.*, (SELECT COUNT(ID) FROM Sorular WHERE OyunID = Oyunlar.ID) AS Sorular, (SELECT COUNT(DISTINCT KatilimciPerNo) FROM Katilimcilar WHERE OyunID = Oyunlar.ID GROUP BY OyunID) AS KatilimciSayisi FROM Oyunlar WHERE Active=1 AND (getdate() BETWEEN BegDa AND EndDa) AND ID='" & ID & "'"
    Dim CMD As New SqlCommand(SQL, Conn1)
    Dim RS As SqlDataReader = CMD.ExecuteReader()
    If RS.Read Then
    If IsDBNull(RS.Item("SoruSayisi")) Then Response.Redirect("Default.aspx?id=" & Request.QueryString("id"))
    lbl_Baslik.Text = RS.Item("OyunAdi")
    ltr_Aciklama.Text = RS.Item("Aciklama")
    lbl_Puan.Text = "0"
    Timer1.Enabled = False
    pnl_Start.Visible = True
    Session("OynamaSayisi") = RS.Item("OynamaSayisi")
    Session("SoruSayisi") = RS.Item("SoruSayisi")
    Session("ToplamSure") = RS.Item("Sure")
    Session("Sure") = RS.Item("Sure")
    Session("Soru") = 0
    Session("Puan") = 0
    Session("DogruCevapSayisi") = 0
    Session("Yuzde50") = True
    Session("Pas") = True
    Session("Sorular") = ""
    Session("Cevaplar") = ""
    If Session("SoruSayisi") > 0 And RS.Item("Sorular") < Session("SoruSayisi") Then Session("SoruSayisi") = RS.Item("Sorular") - 1
    If Session("SoruSayisi") > 0 Then Session("SoruSayisi") += 1
    If IsDBNull(RS.Item("KatilimciSayisi")) Then lbl_YarismaciSayisi.Text = 0 Else lbl_YarismaciSayisi.Text = RS.Item("KatilimciSayisi")
    RS.Close()
    RS = Nothing
    End If
    hdn_Control.Value = New Guid().ToString
    Session("PageGuid") = hdn_Control.Value
    End Using
    lbl_Sure.Text = "SÜRE: " & MySettings.ConvertSeconds(Session("Sure"))
    Else
    If hdn_Control.Value <> Session("PageGuid") Then Response.Redirect("Default.aspx?id=" & Request.QueryString("id"))
    End If
    End Sub
    Protected Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    If Session("Sure") > 0 Then
    Session("Sure") -= 1
    lbl_Sure.Text = "SÜRE: " & MySettings.ConvertSeconds(Session("Sure"))
    Else
    Finish()
    End If
    End Sub
    Protected Sub btn_YeniOyun_Click(sender As Object, e As System.EventArgs) Handles btn_YeniOyun.Click
    Session.Abandon()
    Response.Redirect("Default.aspx?id=" & Request.QueryString("id"))
    End Sub
    Protected Sub btn_TekrarClick(sender As Object, e As System.EventArgs) Handles btn_Tekrar.Click
    Session.Abandon()
    Response.Redirect("Default.aspx?id=" & Request.QueryString("id"))
    End Sub
    Protected Sub btn_BaslaClick(sender As Object, e As System.EventArgs) Handles btn_Basla.Click
    If Not Session("OynamaSayisi") = 99 Then
    If PerNo2Name.PerNo2Name.Personel.getName(txt_PerNo.Text.ToString) = "Noname" Or PerNo2Name.PerNo2Name.Personel.getName(txt_PerNo.Text.ToString) = "" Then Response.Redirect("Default.aspx?id=" & Request.QueryString("id"))
    End If
    Using Conn2 As New SqlConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString)
    Conn2.Open()
    Dim CMD_Kontrol As New SqlCommand("SELECT COUNT(ID) FROM Katilimcilar WHERE OyunID='" & Request.QueryString("id") & "' AND KatilimciPerNo = '" & txt_PerNo.Text.ToString & "' AND DAY(OynamaTarihi)=DAY(getdate())", Conn2)
    Session("OynamaLimiti") = CMD_Kontrol.ExecuteScalar
    End Using
    If Session("OynamaLimiti") >= Session("OynamaSayisi") Then
    pnl_Start.Visible = False
    ltr_Aciklama.Visible = False
    pnl_Kota.Visible = True
    Else
    Using Conn3 As New SqlConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString)
    Conn3.Open()
    Dim CMD As New SqlCommand("INSERT INTO Katilimcilar(KatilimciPerNo, OyunID, IP) VALUES('" & txt_PerNo.Text.ToString & "', '" & Request.QueryString("id") & "', '" & Request.ServerVariables("Remote_addr") & "') select ID = scope_identity()", Conn3)
    Session("newID") = CMD.ExecuteScalar
    End Using
    lbl_PerNo.Text = txt_PerNo.Text
    'lbl_PerNo.Text = PerNo2Name.PerNo2Name.Personel.getName(txt_PerNo.Text)
    pnl_Start.Visible = False
    ltr_Aciklama.Visible = False
    pnl_Step.Visible = True
    Cevapla()
    Timer1.Enabled = True
    End If
    End Sub
    Protected Sub btn_CevapClick(sender As Object, e As CommandEventArgs)
    If Session("Sure") = 0 Then Response.Redirect("Default.aspx?id=" & Request.QueryString("id"))
    Dim btn As Button = sender
    btn_Cevap1.Enabled = False
    btn_Cevap2.Enabled = False
    btn_Cevap3.Enabled = False
    btn_Cevap4.Enabled = False
    If btn.CommandArgument = True Then
    btn.CssClass = "btnTrue"
    Session("DogruCevapSayisi") += 1
    Session("Puan") += 10
    lbl_Puan.Text = Session("Puan")
    Using Conn3 As New SqlConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString)
    Conn3.Open()
    Dim CMD As New SqlCommand("UPDATE Katilimcilar Set DogruCevapSayisi = '" & Session("DogruCevapSayisi") & "', Puan = '" & Session("Puan") & "' WHERE ID='" & Session("newID") & "'", Conn3)
    CMD.ExecuteNonQuery()
    End Using
    Else
    btn.CssClass = "btnFalse"
    If btn_Cevap1.CommandArgument = True And btn.ID <> "btn_Cevap1" Then btn_Cevap1.CssClass = "btn_Correct"
    If btn_Cevap2.CommandArgument = True And btn.ID <> "btn_Cevap2" Then btn_Cevap2.CssClass = "btn_Correct"
    If btn_Cevap3.CommandArgument = True And btn.ID <> "btn_Cevap3" Then btn_Cevap3.CssClass = "btn_Correct"
    If btn_Cevap4.CommandArgument = True And btn.ID <> "btn_Cevap4" Then btn_Cevap4.CssClass = "btn_Correct"
    End If
    btn_Pass.Enabled = False
    btn_Yuzde50.Enabled = False
    btn_SonrakiSoru.Enabled = True
    'SESSION KONTROL EDİLİP EKRANA YAZDIRILIYOR.
    'lbl_PerNo.Text = lbl_PerNo.Text & "<hr>" & Session.SessionID & "<br>"
    'For Each x In Session
    ' lbl_PerNo.Text = lbl_PerNo.Text & x & " - " & Session(x) & "<br>"
    'Next
    End Sub
    Protected Sub btn_PassClick(sender As Object, e As System.EventArgs) Handles btn_Pass.Click
    Session("Pas") = False
    Session("Soru") -= 1
    Cevapla()
    End Sub
    Protected Sub btn_SonrakiSoruClick(sender As Object, e As System.EventArgs) Handles btn_SonrakiSoru.Click
    Dim btn As Button = sender
    btn.Enabled = False
    Cevapla()
    End Sub
    Protected Sub btn_Yuzde50Click(sender As Object, e As System.EventArgs) Handles btn_Yuzde50.Click
    Session("Yuzde50") = False
    btn_Yuzde50.Enabled = False
    If btn_Cevap1.CommandArgument = True Then
    btn_Cevap2.Enabled = False
    btn_Cevap2.CssClass = "btn_Disabled"
    Else
    btn_Cevap1.Enabled = False
    btn_Cevap1.CssClass = "btn_Disabled"
    End If
    If btn_Cevap3.CommandArgument = True Then
    btn_Cevap4.Enabled = False
    btn_Cevap4.CssClass = "btn_Disabled"
    Else
    btn_Cevap3.Enabled = False
    btn_Cevap3.CssClass = "btn_Disabled"
    End If
    End Sub
    Protected Sub Cevapla()
    If Session("Soru") < Session("SoruSayisi") - 1 Then
    Session("Soru") += 1
    lbl_SoruNo.Text = "SORU: " & Session("Soru") & " / " & Session("SoruSayisi") - 1
    Dim SoruID = SoruGetir(Request.QueryString("id"))
    Using Conn5 As New SqlConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString)
    Conn5.Open()
    Dim CMD_Soru As New SqlCommand("Select Soru FROM Sorular WHERE ID='" & SoruID & "'", Conn5)
    lbl_Soru.Text = CMD_Soru.ExecuteScalar
    End Using
    Dim Cevap1 As String() = CevapGetir(SoruID)
    btn_Cevap1.CommandName = Cevap1(0)
    btn_Cevap1.Text = Cevap1(1)
    btn_Cevap1.CommandArgument = Cevap1(2)
    Dim Cevap2 As String() = CevapGetir(SoruID)
    btn_Cevap2.CommandName = Cevap2(0)
    btn_Cevap2.Text = Cevap2(1)
    btn_Cevap2.CommandArgument = Cevap2(2)
    Dim Cevap3 As String() = CevapGetir(SoruID)
    btn_Cevap3.CommandName = Cevap3(0)
    btn_Cevap3.Text = Cevap3(1)
    btn_Cevap3.CommandArgument = Cevap3(2)
    Dim Cevap4 As String() = CevapGetir(SoruID)
    btn_Cevap4.CommandName = Cevap4(0)
    btn_Cevap4.Text = Cevap4(1)
    btn_Cevap4.CommandArgument = Cevap4(2)
    If Session("Soru") = Session("SoruSayisi") - 1 Then btn_SonrakiSoru.Text = "Oyunu bitir" Else btn_SonrakiSoru.Text = "Sonraki Soru"
    If Session("Yuzde50") = True Then btn_Yuzde50.Enabled = True Else btn_Yuzde50.Enabled = False
    If Session("Pas") = True Then btn_Pass.Enabled = True Else btn_Pass.Enabled = False
    btn_SonrakiSoru.Enabled = False
    btn_Cevap1.Enabled = True
    btn_Cevap2.Enabled = True
    btn_Cevap3.Enabled = True
    btn_Cevap4.Enabled = True
    btn_Cevap1.CssClass = "btn_Soru"
    btn_Cevap2.CssClass = "btn_Soru"
    btn_Cevap3.CssClass = "btn_Soru"
    btn_Cevap4.CssClass = "btn_Soru"
    Else
    Finish()
    End If
    End Sub
    Protected Sub Finish()
    pnl_Step.Visible = False
    pnl_Complete.Visible = True
    Timer1.Enabled = False
    UpdatePanel2.Update()
    Dim PuanSure As Double = 0
    'If Session("DogruCevapSayisi") > 0 Then PuanSure = FormatNumber(Integer.Parse(Session("Sure")) * 10 / Integer.Parse(Session("ToplamSure")) * Integer.Parse(Session("DogruCevapSayisi")), 2)
    If Session("DogruCevapSayisi") > 0 Then PuanSure = FormatNumber(Integer.Parse(Session("Sure")) * 0.25, 2)
    Using Conn6 As New SqlConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString)
    Conn6.Open()
    Dim SQL_PuanGuncelle As String = "UPDATE Katilimcilar Set KalanSure='" & Integer.Parse(Session("Sure")) & "', Puan='" & Replace(Integer.Parse(Session("Puan")) + PuanSure, ",", ".") & "' WHERE ID='" & Integer.Parse(Session("newID")) & "'"
    Dim CMD_PuanGuncelle As New SqlCommand(SQL_PuanGuncelle, Conn6)
    CMD_PuanGuncelle.ExecuteNonQuery()
    'Dim CMD_Siralama As New SqlCommand("SELECT SiraNo FROM (SELECT ROW_NUMBER() OVER(ORDER BY MAX(Puan) DESC) AS SiraNo, KatilimciPerNo, MAX(Puan) as Puan FROM Katilimcilar WHERE OyunID='" & Request.QueryString("id") & "' GROUP BY KatilimciPerNo) as t WHERE KatilimciPerNo='" & txt_PerNo.Text.ToString & "'", Conn.myConn)
    'Dim Siralama As Integer = 1
    'Siralama = CMD_Siralama.ExecuteScalar
    End Using
    ltr_Sonuc.Text = "<br /><br /><table align='center' cellpadding='2' style='margin-left:auto; margin-right:auto; text-align:left;'>"
    'ltr_Sonuc.Text += "<tr><td>Yarışmadaki sıranız: </td><td><b>" & Siralama & "</b></td></tr>"
    ltr_Sonuc.Text += "<tr><td>Toplam soru sayısı: </td><td><b>" & Session("SoruSayisi") - 1 & "</b></td></tr>"
    ltr_Sonuc.Text += "<tr><td>Doğru cevap sayısı: </td><td><b>" & Session("DogruCevapSayisi").ToString & "</b></td></tr>"
    ltr_Sonuc.Text += "<tr><td>Artan süre: </td><td><b>" & MySettings.ConvertSeconds(Session("Sure").ToString) & "</b></td></tr>"
    ltr_Sonuc.Text += "<tr><td>Doğru sorulardan kazandığınız puan: </td><td><b>" & Session("Puan").ToString & "</b></td></tr>"
    ltr_Sonuc.Text += "<tr><td>Artan süreden kazandığınız puan: </td><td><b>" & PuanSure & "</b></td></tr></table></br><hr />"
    ltr_Sonuc.Text += "TOPLAM PUAN: <b>" & Integer.Parse(Session("Puan")) + PuanSure & "</b><br />"
    Session.Clear()
    Session.Abandon()
    End Sub
    Private Function SoruGetir(id As String) As String
    Dim SQL_Soru As String = ""
    If Len(Session("Sorular")) > 0 Then
    SQL_Soru = " WHERE ID NOT IN(" & Session("Sorular") & ") AND OyunID='" & id & "'"
    Else
    SQL_Soru = " WHERE OyunID='" & id & "'"
    End If
    Using Conn7 As New SqlConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString)
    Conn7.Open()
    Dim CMD_SoruID As New SqlCommand("Select TOP 1 ID FROM Sorular" & SQL_Soru & " ORDER BY newid()", Conn7)
    Dim SoruID As String = CMD_SoruID.ExecuteScalar
    If Len(Session("Sorular")) > 0 Then Session("Sorular") = Session("Sorular") & ", "
    Session("Sorular") = Session("Sorular") & SoruID
    Session("Cevaplar") = ""
    Return SoruID
    End Using
    End Function
    Private Function CevapGetir(id As String) As String()
    Dim Cevap(3) As String
    Dim SQL_Cevap As String = ""
    If Len(Session("Cevaplar")) > 0 Then
    SQL_Cevap = " WHERE ID NOT IN(" & Session("Cevaplar") & ") AND SoruID='" & id & "'"
    Else
    SQL_Cevap = " WHERE SoruID='" & id & "'"
    End If
    Using Conn8 As New SqlConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString)
    Conn8.Open()
    Dim CMD_Cevap As New SqlCommand("SELECT TOP 1 ID, Cevap, Dogru FROM Cevaplar" & SQL_Cevap & " ORDER BY newid()", Conn8)
    Dim RD As SqlDataReader = CMD_Cevap.ExecuteReader()
    If RD.Read Then
    Cevap(0) = RD.Item(0)
    Cevap(1) = RD.Item(1)
    Cevap(2) = RD.Item(2)
    If Len(Session("Cevaplar")) > 0 Then Session("Cevaplar") = Session("Cevaplar") & ", "
    Session("Cevaplar") = Session("Cevaplar") & RD.Item(0)
    End If
    RD.Close()
    RD = Nothing
    Return Cevap
    End Using
    End Function
    </script>
    <asp:Content ID="MyHeader" ContentPlaceHolderID="CPH_Title" Runat="Server">
    <h1><asp:Label ID="lbl_Baslik" runat="server" /></h1>
    <script type="text/javascript">
    $(document).ready(function () {
    $(document).keydown(function (e) {
    if ((e.ctrlKey && (e.which == 110 || e.which == 78)) || (e.ctrlKey && (e.which == 75 || e.which==116)) || e.keyCode == 110)
    {return false};
    </script>
    </asp:Content>
    <asp:Content ID="MyContent" ContentPlaceHolderID="CPH" Runat="Server">
    <asp:ScriptManager ID="ScriptManager" runat="server" EnableScriptGlobalization="true" />
    <asp:Timer ID="Timer1" runat="server" Interval="1000" /><br />
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
    <asp:HiddenField id="hdn_Control" runat="server" />
    <h3><asp:Literal ID="ltr_Aciklama" runat="server" /></h3>
    <br /><br />
    <table style="width:100%;">
    <tr>
    <td style="text-align:left; width:30%"><asp:Label ID="lbl_PerNo" runat="server" Font-Size="16px" /></td>
    <td style="text-align:center; width:40%;"><asp:Label ID="lbl_Sure" runat="server" Font-Size="16px" /></td>
    <td style="text-align:right; width:30%;"><asp:Label ID="lbl_PuanTitle" runat="server" Font-Size="16px" Text="PUAN: " /><asp:Label ID="lbl_Puan" runat="server" Font-Size="16px" /></td>
    </tr>
    </table>
    </ContentTemplate>
    <Triggers>
    <asp:AsyncPostBackTrigger ControlID="Timer1" />
    </Triggers>
    </asp:UpdatePanel>
    <hr /><br />
    <asp:Panel ID="pnl_Start" runat="server" Visible="false" DefaultButton="btn_Basla">
    <div style="text-align:center">
    <asp:Label ID="lbl_Kota" runat="server" Text="Yarışma başlıyor!..." CssClass="lbl_Kota" /><br /><br />
    Personel No
    <asp:RequiredFieldValidator ID="RFV_txtPerNo" runat="server"
    ControlToValidate="txt_PerNo" EnableViewState="False"
    ErrorMessage="Lütfen personel numaranızı girin." SetFocusOnError="True"
    ValidationGroup="PerNo" Text="*" Display="Dynamic" />
    <asp:RegularExpressionValidator ID="REV_txtPerNo" runat="server"
    ControlToValidate="txt_PerNo" EnableViewState="False"
    ErrorMessage="Lütfen 8 haneli personel numaranızı giriniz."
    SetFocusOnError="True" ValidationExpression="\d{8}?"
    ValidationGroup="PerNo" Text="*" Display="Dynamic" />
    <br />
    <asp:TextBox ID="txt_PerNo" runat="server" MaxLength="8" AutoCompleteType="Disabled" ValidationGroup="PerNo" CssClass="txt_PerNo" />
    <br /><br />
    <asp:Button id="btn_Basla" runat="server" Text="Başla" ValidationGroup="PerNo" CssClass="btn_Basla" />
    <br /><br />
    Yarışmaya katılan sayısı: <asp:Label ID="lbl_YarismaciSayisi" runat="server" />
    <asp:ValidationSummary ID="ValidationSummary" runat="server" ShowMessageBox="True" ShowSummary="False" ValidationGroup="PerNo" />
    </div>
    </asp:Panel>
    <asp:Panel ID="pnl_Kota" runat="server" Visible="false" DefaultButton="btn_Tekrar">
    <div style="text-align:center">
    <h3>Üzgünüm!</h3><br /><br />
    Bu günlük oynama kotanızı doldurdunuz, yarın şansınızı tekrar deneyiniz.
    <br /><br />
    <asp:Button id="btn_Tekrar" runat="server" Text="Tamam" CssClass="btn_Basla" />
    <br /><br />
    </div>
    </asp:Panel>
    <asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional">
    <ContentTemplate>
    <asp:Panel ID="pnl_Step" runat="server" Visible="false" DefaultButton="btn_SonrakiSoru">
    <asp:Label ID="lbl_SoruNo" runat="server" /><br />
    <h3><asp:Label ID="lbl_Soru" runat="server" /></h3><br /><br />
    <div style="text-align:center">
    <asp:Button ID="btn_Cevap1" runat="server" Text="Cevap 1" OnCommand="btn_CevapClick" CssClass="btn_Soru" />
    <asp:Button ID="btn_Cevap2" runat="server" Text="Cevap 2" OnCommand="btn_CevapClick" CssClass="btn_Soru" />
    <br />
    <asp:Button ID="btn_Cevap3" runat="server" Text="Cevap 3" OnCommand="btn_CevapClick" CssClass="btn_Soru" />
    <asp:Button ID="btn_Cevap4" runat="server" Text="Cevap 4" OnCommand="btn_CevapClick" CssClass="btn_Soru" />
    </div>
    <br /><br /><hr />
    <table style="width:100%">
    <tr>
    <td>
    <asp:Button id="btn_Yuzde50" runat="server" Text="Yüzde 50" CssClass="btn_Sub" />
    <asp:Button id="btn_Pass" runat="server" Text = "Pas Geç" CssClass="btn_Sub" />
    </td>
    <td style="float:right"><asp:Button id="btn_SonrakiSoru" runat="server" Enabled="false" Text = "Sonraki Soru" CssClass="btn_Sub" /></td>
    </tr>
    </table>
    </asp:Panel>
    <asp:Panel ID="pnl_Complete" runat="server" Visible="false">
    <div style="text-align:center">
    <b>YARIŞMA SONA ERDİ.</b><br />
    <asp:Literal ID="ltr_Sonuc" runat="server" /><br /><br />
    <asp:Button ID="btn_YeniOyun" runat="server" Text="Yeni Oyun" CssClass="btn_Sub" /><br />
    </div>
    </asp:Panel>
    </ContentTemplate>
    </asp:UpdatePanel>
    </asp:Content>

    Sure, but i think when i get the questions from sql and put them to controls conflict may happens. Is the controls unique for each session users? I dont understand what the problem is.
    That is why I adviced you to visit the IIS forum. A session is a part of IIS. 
    And forget the code, your question is clear enough but it is a while ago I did use it. (It is an old way of using webpages)
    Currently you use mostly IsPostBack but that is then again a question for the ASP.Net forums.
    http://msdn.microsoft.com/en-us/library/system.web.ui.page.ispostback(v=vs.110).aspx
    Success
    Cor

  • Help with JSP, session, login, JDBC.

    This is the template login.jsp file I have at the moment.
    <%@ page errorPage="errorPage.jsp" %>
    <%
      String login = (String)request.getParameter("loginname");
      if (login == null || login.equals("")) {
    %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Final//EN">
    <HEAD>
    <TITLE>Login Page</TITLE>
    <STYLE>
    <!--
    font.loginhead {
      font-family: Arial,Helvetica,sans-serif;
      font-size:12pt; font-weight: 600; color: #000000;
    font.loginform {
      font-family: Arial,Helvetica,sans-serif;
      font-size:10pt; font-weight: 600; color: #ffffff;
    -->
    </STYLE>
    </HEAD>
    <BODY>
    <jsp:include page="debug.jsp" flush="true" />
    <CENTER>
    <FONT CLASS="loginhead">
    LOGIN REQUIRED:
    </FONT>
    <BR>
    <FORM NAME="loginform" METHOD=post>
    <TABLE BGCOLOR=#990022 BORDER=0 CELLPADDING=5 CELLSPACING=0>
    <TR><TD ALIGN=right>
    <FONT CLASS="loginform">
    Login Name:
    </FONT>
    </TD><TD ALIGN=left>
    <FONT CLASS="loginform">
    <INPUT TYPE=text NAME="loginname" SIZE=10>
    </FONT>
    </TD></TR>
    <TR><TD ALIGN=right>
    <FONT CLASS="loginform">
    Password:
    </FONT>
    </TD><TD ALIGN=left>
    <FONT CLASS="loginform">
    <INPUT TYPE=password NAME="loginpassword" SIZE=10>
    </FONT>
    </TD></TR>
    <TR><TD COLSPAN=2 ALIGN=center>
    <FONT CLASS="loginform">
    <INPUT TYPE=SUBMIT VALUE="Login">
    </FONT>
    </TD></TR>
    </TABLE>
    </FORM>
    </CENTER>
    </BODY>
    </HTML>
    <%
      } else {
       Checking against database that username and password are correct.
        session.putValue("login", login);
        session.setMaxInactiveInterval(600);
        String loginpoint
           = (String)session.getValue("loginpoint");
        if (loginpoint == null) {
          StringBuffer defaultpoint = new StringBuffer();
          defaultpoint.append(request.getScheme())
                      .append("://")
                      .append(request.getServerName())
                      .append("/");
          loginpoint = defaultpoint.toString();
        } else {
          session.removeValue("loginpoint");
        response.sendRedirect(loginpoint); 
      }I know as much as how connect to the database, create a statement and check to see if the username and password are correct, I dont know how to actually take what the user has typed in and put it in an mysql query. I have an idea that maybe I can convert Login and Loginpassword to Strings but I don't know how to do this.
    This is how I plan to connect to the database above
    //here I need to have login and loginpasword in separate Strings so I can use them in a query.
    Connection connection;
    Class.forName("com.mysql.jdbc.Driver").newInstance();
    connection = DriverManager.getConnection("jdbc:mysql://localhost/Users");
    Statement statement=connection.createStatement();
    String qry="select PassWord from customers where UserName='"+stringLogin+"'";
    ResultSet rs= statement.executeQuery(qry);In my login.jsp file above I don't understand the following code, and why it is needed. Can someone explain please.
    session.putValue("login", login);
        session.setMaxInactiveInterval(600);
        String loginpoint
           = (String)session.getValue("loginpoint");
        if (loginpoint == null) {
          StringBuffer defaultpoint = new StringBuffer();
          defaultpoint.append(request.getScheme())
                      .append("://")
                      .append(request.getServerName())
                      .append("/");
          loginpoint = defaultpoint.toString();
        } else {
          session.removeValue("loginpoint");
        response.sendRedirect(loginpoint); 
      }Hope you can understand what I'm trying to explain what my problems are.

    Im not sure what your exact question is. However, I can
    throw a few things out there.
    1) You need an action to handle the form request
    <FORM NAME="loginform" METHOD=post ACTION="login.jsp">2) Then get the username and password from the request
    String uname = (String)request.getParameter("loginname");
    String pass = (String)request.getParameter("loginpassword");3)Then you can just add them to the query string
    String qry="select PassWord from customers where UserName='"+uname+"'";4) Also check for valid password
    ResultSet rs= statement.executeQuery(qry);
    if(rs.next()) {
        String p = res.getString("PassWord");
             if (p.equals(pass)) {
                //valid user
                session.setAttribute("valid_user", "true");
                // now you can get valid_user from session at top of login.jsp
    }5) I cant find where loginpoint is set in the session, but the idea
    of the code below appears to be the logic of where to direct the user
    which I think would be dependent upon the validation of the user.
    session.putValue("login", login);
        session.setMaxInactiveInterval(600);
        String loginpoint
           = (String)session.getValue("loginpoint");
        if (loginpoint == null) {
          StringBuffer defaultpoint = new StringBuffer();
          defaultpoint.append(request.getScheme())
                      .append("://")
                      .append(request.getServerName())
                      .append("/");
          loginpoint = defaultpoint.toString();
        } else {
          session.removeValue("loginpoint");
        response.sendRedirect(loginpoint); 
      }You might try splitting the login into two pages to start out if you are having
    some difficulty.

  • What causes slow response times

    In any session, my computer response times slow down and I have to close all apps and restart to get the system to speed up again. Is this a CPU, hard drive or similar problem? Any solutions?

    Hi,
    I expect the error details in CF9\runtime\logs\coldfusion-out.log will like provide a clue as to problem.
    For a more long term plan I think you should do what you can to migrate the ACCESS data to SQL or some other database.
    HTH, Carl.

  • Remove Session?

    How can I remove a session in order that when I click the back button of my browser the session is ended?
    So for example from the A servlet I my call the exit session and I shouldnt be able to turn back!
    I tryied HttpSession session=request.getSession();
                   String[] list=(String[])session.getAttribute("session");
                   session.removeAttribute("session");but when I press the back button I am steel logged into my account. The A session only gets the session like this:
    response.setContentType("text/html");
                  PrintWriter out = response.getWriter();
                  HttpSession cart=request.getSession();

    booker wrote:
    How can I remove a session in order that when I click the back button of my browser the session is ended?The browser back button usually loads the page from the browser cache. No actual request is been fired to the server.
    To disable browser cache, add cache-control, pragma and expires response headers accordingly.

Maybe you are looking for