Change url URLConnection

I want to connect from an applet to a servlet with URLConnection. There are 2 ways to connect: in the beginning of each session you connect to the applet to get a list of drawn shapes. I create an URLConnection object and connect to the servlet. I go into the doGet-method, retrieve the values from a database and returns an arraylist. I use the doPost method to save new shapes.
When i delete a shape from the canvas, i want to return to the doGet method by adding a parameter to the url. E.g ../ShapeServlet?shapeid=20. The problem is, the url is correct, but the URLConnection object keeps using the url from the beginning of the session (without the parameter). I use 2 seperate objects so it's kinda weird he keeps connecting to the servlet with the first url. I also tried to do it hard-coded, but it doesn't work either.
Here's the code:
Load the shapes from the applet:
     public ArrayList loadShapes()
          ObjectInputStream inputFromServlet = null;
          try{
               URL servlet = new URL(url);
               URLConnection con = servlet.openConnection();
               con.setUseCaches(false);
               inputFromServlet = new ObjectInputStream(con.getInputStream());
               ArrayList lijst = (ArrayList) inputFromServlet.readObject();
               inputFromServlet.close();
               return lijst;
          catch(MalformedURLException e){ e.printStackTrace(); }
          catch(IOException e){ e.printStackTrace(); }
          catch(ClassNotFoundException e){ e.printStackTrace(); }
          return null;
     }Delete a shape:
     /** Shape weggooien */
     public void deleteShape(int shapeid)
          try{
               String a = "http://PCPST2:8080/AppletViewer/ShapeServlet?shapeid=" + shapeid;
               URL servlet = new URL(a);
               System.out.println("DELETESHAPE: " + a);
               URLConnection connectionTwo = servlet.openConnection();               
               connectionTwo.setUseCaches(false);               
          catch(MalformedURLException e){ e.printStackTrace(); }
          catch(IOException e){ e.printStackTrace(); }
     }

it seems that deleteShape() doesn't connect to the servlet. Is it possible that >the servlet rejects the connection?No, he simply doesnt connect :), wierd behaviour, but that's how the default implementation of URLConnection and HttpURLConnection works.
The following is from javadocs
The connection object is created by invoking the openConnection method on a URL.
The setup parameters and general request properties are manipulated.
The actual connection to the remote object is made, using the connect method.
The remote object becomes available. The header fields and the contents of the remote object can be accessed.
You havent used the connect() method in your deleteShapes() method.
Hang on, even if you use it, it wouldnt connect to the Servlet.
I did some reading up on this and again javadcos has this to say about the connect() method
Operations that depend on being connected, like getContentLength, will implicitly perform the connection, if necessary.
So what I did was forced connect() by getting the input stream from the connection.
In your code, though the deleteShapes() method doesnt have anything to read from the Servlet, create a reader and make a dummy readLine() call.
You would see that it connects now. Add the code below to your deleteShapes() method.
        InputStreamReader reader = new InputStreamReader(conn.getInputStream());       
        System.out.println((new BufferedReader(reader)).readLine());
         //this will return null, coz there's nothing to be read, and
         //yet it would ensure connection.Hope this helps,
ram.

Similar Messages

  • How to change url of bsp page

    Hi experts
    I have created a BSP application , In login pafe i want to change  URL which we use for TEST .
    Or can can i redirect to another url , when TEST the page.
    Thanks & Regards
    Prashant Gupta

    Hi Prashant,
    Re-directing to another URL on load of page is a very simple piece of HTML code.Put this on the layout of page from where you want to re-direct to the other URL.
    <html>
    <head>
      <metas http-equiv="refresh" content="0;url=http://sdn.sap.com">
    </head>
    </html>
    Here the important line is the 3rd line which begins with "<metas". The operation is "refresh" which means to "refresh" the current page with the information that follows. The content begins with a zero, which is the number of seconds to wait, and then the URL that you should be taken to.
    So the above code would re-direct you to the http://sdn.sap.com page as soon as you log in.
    Hope this helps!
    PS : meta changed to metas to allow adding of the code.
    Regards,
    Saurabh

  • Firefox 3.6.14 shows URl but displays nothing, changing URLs crashes it

    After Firefox 3.6.14 installed itself on my Mac, I have not been able to see any page and if I change URLs, it crashes. How can I get a back copy of Firefox?

    After Firefox 3.6.14 installed itself on my Mac, I have not been able to see any page and if I change URLs, it crashes. How can I get a back copy of Firefox?

  • Changing URL for E_BUSINESS system

    Hi,
    how to change URL for E_BUSINESS system ? Should we only edit contexte .xml files and launch autoconfig? Which parameteres ?
    Many thanks.

    Hsawwan, thank you. I did this :
    to modify "s_login_page" and run AutoConfig. Make sure you have the latest AutoConfig patch applied (Patch 5985992 - TXK AUTOCONFIG ROLLUP PATCH Q (JUL/AUG 2007))
    Now it is OK for login page. But :
    1-when entering in E_BUSINESS or OAM it goes back to ancient URL ? Should we change some other parameters ?
    2-when loging in for example as sysadmin, first time it fails with this message :
    You have insufficient privileges for the current operation.
    we login again and it is ok , user can enter.
    Many thanks.

  • Changing URLs on multiple pages

    Hi,
    after Migration from SP2007 to 2010 I have to Change URLs on multiple (about 400) pages. The pages contain XSLTListViewWebparts, DataFormWebparts, ListViewWebparts and XSLT with hardcoded URLs. About 20 URLs per page.
    Can I achieve this with some scripts? I am able to write a script for the Webpart properties, but I don't know how to modify the XSLT. Best way would be to simply change the source code, but until now I was just able to modify the "ghosted"
    part of the source code. It didn't affect the Webparts and so on.
    Thanks,
    Stefan

    Hi Stefan,
    Per my understanding, you might want to change URLs on your pages which are generated from XSLT.
    A solution can be like this: as the URLs are hardcoded in these pages, we can iterate through the URLs which you want to modify in each page using JavaScript. Then add the JavaScript
    into the master page, it would take effect on the pages which referenced this master page.
    About
    how to add custom script into SharePoint master page:
    http://techtrainingnotes.blogspot.com/2012/05/adding-javascript-and-css-to-sharepoint.html
    Feel free to reply if there may be questions about the solution above.
    Thanks
    Patrick Liang
    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact
    [email protected]

  • URL,URLConnection,HttpURLConnection &&Session

    Hi,all
    I want to access a web page by URL/URLConnection/HttpURLConnection
    the page need a login user,it check the Session,if the session is null,then it redirect to the login page
    Now I have the user ID and Password ,and I can complete my login by URL Class
    but when I access the wanted page after I login,it's still return that the session is not set.
    below is the Code Segment,thanx in advance
    String urlStr = "http://buyc:8080/ecommerce/oa/login.jsp?txtUsername=sh001&txtPwd=111111&role=storeman";
    URL url = new URL(urlStr);
    HttpURLConnection hurlc =(HttpURLConnection) url.openConnection();
    hurlc.setFollowRedirects(true);
    hurlc.setInstanceFollowRedirects(true);
    hurlc.setUseCaches(true);
    hurlc.connect();//if check login successfully in login.jsp,it will redirect to a check page.
    InputStream is=hurlc.getInputStream();//
    byte tmpbyte[]=new byte[is.available()];
    int num=is.read(tmpbyte);
    String result=new String(tmpbyte);
    System.out.println("the " + num + ":" + result);

    IIRC, you use the UrlConnection's methods getHeaderField and getHeaderFields to get the cookies, and then setRequestProperty to set the cookies on subsequent connections. These methods are inherited by HttpUrlConnection.
    There may be a library out there to make this stuff easier, but I don't think it's in the standard libraries.

  • Change url connection to socket

    hello i have a problem about a socket connection can you help me
    i want to change url connection to socket connection
    here is
              java.net.URL url = new java.net.URL("http://64.74.75.74/approot/webapp/ZOR/bare");
              connection = new sun.net.www.protocol.http.HttpURLConnection(url, " ", 0);
              connection.setRequestMethod("POST");
              connection.setDoInput(true);
              connection.setDoOutput(true);
              connection.setUseCaches(false);
              java.io.ObjectOutputStream out = new java.io.ObjectOutputStream(connection.getOutputStream());
              out.writeObject(getTextFieldGiden().getText());
              out.flush();
              out.close();
              return (String) (new java.io.ObjectInputStream(connection.getInputStream()).readObject());how can i change it to
    socket connection because i must write it in c++
    thank you very much

    why are you replaying if you don' t have a solution peter?
    i have a big c++ project and in it somewhere must do the job the code i send in java do.
    &#304; also want to say i dont want it's c++ code ,i want to know how it can be with java sockets.

  • Proper way to change URL connections

    When viewing a page of search results from Google with the search term "java", I get the following URL: http://www.google.com/search?hl=en&q=java&btnG=Google+Search
    Page 2 is associated with the URL: http://www.google.com/search?q=java&hl=en&lr=&safe=off&start=10&sa=N
    In order to change pages programmatically, do I need to do anything with the first URLConnection before creating a second URLConnection?

    All google needs is q and start, so your first page would be:
    http://www.google.co.uk/search?q=test&start=0
    second:
    http://www.google.co.uk/search?q=test&start=10
    http://www.google.co.uk/search?q=test&start=1000
    Or you could use the Google Web API.

  • Form login with java, then change URL

    this is my problem, theres a site where I need to login with a login + pass. now when I try to take a new url (on the same host) I'm back at the login page, so basically I want to login, and then keep that login to parse several pages on the server... I didn't write this code myself, but it works for the login :p now I just need to change the url in the same connection I guess
    String argus[]= {url,"name",name,"password",password};
              URL u = new URL(argus[0]);
              String postdata = URLEncoder.encode(argus[1]) + "=" + URLEncoder.encode(argus[2]);
              for (int i=3;i+1<argus.length;i+=2) {
              postdata = postdata + "&" + URLEncoder.encode(argus) + "=" + URLEncoder.encode(argus[i+1]);
              URLConnection uc = u.openConnection();
              uc.setDoOutput(true);
              OutputStreamWriter out =
              new OutputStreamWriter(uc.getOutputStream(),"ASCII");
              out.write(postdata);
              out.close();
         String s;
              while ((s = r.readLine()) != null) {
              System.out.println(s);
    so far it works perfectly, but now I need to get another html page on that server, but when I create a new URL it goes back to the login page...
    any ideas ?

    The page probably sets a cookie. This article tells about one way to handle cookies:
    http://www.javaworld.com/javaworld/jw-04-2002/jw-0426-cookie.html

  • How to Change URL of BPA after clicking on Open Document in PO Notification for India Localization?

    In the Purchase Order Approval workflow notification , there are two links at the bottom of page under heading REFERENCES,
    - view PDF
    - open document
    So when we click on open document, the Oracle Forms loads and  purchase order screen will appear in the screen.
    In case of India localization, for standard PO the India local screen opens, where we can see the taxes by clicking on Taxes Button.
    But in case of blanket purchase agreements, when we click on open document link from the notification,we are routed to the application with the screen of global purchase order, instead it
    should go to Purchase Orders(Localization).
    We want to move to the India local po screen for BPA.
    So please let me know, where I can change the URL for Blanket Purchase Agreements.
    Regards
    Sandeep

    Hi kalyani,
    Please check my inbound plug code...tell me what changes wee need to do and where wee need to add this code...once again thanks for your reply..
    METHOD
    ip_inboundplug.
    **CALL METHOD SUPER->IP_INBOUNDPLUG
    ** EXPORTING
    ** iv_collection = iv_collection.
    DATA: lt_ivr_url_param TYPE tihttpnvp,
    ls_ivr_url_param TYPE ihttpnvp,
    lr_searchcustomer TYPE REF TO if_bol_bo_property_access,
    ls_searchcustomer TYPE crmt_bupa_il_header_search.
    CALL METHOD cl_crm_ui_session_manager=>get_initial_form_fields
    CHANGING
    cv_fields = lt_ivr_url_param.
    lr_searchcustomer ?= me->typed_context->searchcustomer->collection_wrapper->get_current( ).
    CHECK lr_searchcustomer IS BOUND.
    READ TABLE lt_ivr_url_param INTO ls_ivr_url_param WITH KEY name = 'sap-phoneno'. "'sap-phoneno'.
    IF ls_ivr_url_param-value IS NOT INITIAL.
    ls_searchcustomer-telephone = ls_ivr_url_param-value.
    CALL METHOD lr_searchcustomer->set_properties( EXPORTING is_attributes = ls_searchcustomer ).
    eh_onsearch( ).
    ENDIF.
    ENDMETHOD

  • How to change URL of Webservice Model without reconfiguring or creating new

    Hi,
    I have create a WebService Model with DEV url (some Dev URL ) using
    Import WebService Model DEPRECATED option
    Now my application is moving to TEST and PROD.
    Is it possible to change DEV URL in webdynpro application application without reconfiguring MODEL or recreating new
    with TEST and PROD urls.
    Please help me

    Hi,
    You need to use adaptive webservice model to change the webservice URL based on the environment i.e. Dev,Test or production which is availiable in NWDS 2004s environment.
    You can refer to links mentioned in below forum.
    Re: Differnce between adptive web service model and webservice model(depricated
    if you you are using webservice model then you need to write the code to generate URL for end point dynamically based on the application environment.
    and then you need to set EndPoint of webservice model with that URL befroe execution of the model.
    e.g.
    String l_endpointurl ="http://"+ l_Server+ ":"+ l_port+ "/webservice name/Config1?style=document";
    l_modeloobject.modelObject()._setEndPoint(l_endpointurl);
    //if service is secured....
    l_modeloobject.modelObject()._setUser(l_userID);
    l_modeloobject.modelObject()._setPassword(l_pwd);
    l_modeloobject.modelObject().execute();
    Regards,
    Shruti.

  • How to change URL for "Log Out" link in CE?

    We need the Communications Express "Log Out" link to go to a different page to the usual log in page. How can I change this?
    I've found the logout function in the uwc/common/Header.jsp file which looks like:
    function logout() {
      url = "<%= getLogoutURL(request) %>";
      top.window.location = url;
    }and I've found the getLogoutURL fuction in the uwc/js/resourceBundleUtils.js file which looks like:
      public String getLogoutURL(HttpServletRequest request)
        return UWCApplicationHelper.getLogoutURL(request);
      }But I can't find where the URL is actually configured.
    any help would be much appreciated.
    Edited by: brett_ac on Jun 30, 2009 5:05 PM

    brett_ac wrote:
    We need the Communications Express "Log Out" link to go to a different page to the usual log in page. How can I change this?
    I've found the logout function in the uwc/common/Header.jsp file which looks like:
    function logout() {
    url = "<%= getLogoutURL(request) %>";
    top.window.location = url;
    You got it in one. If you wanted the logout button to redirect to google you would set:
    function logout() {
       url = "http://google.com/";
       top.window.location = url;Then restart the web-container.
    and I've found the getLogoutURL fuction in the uwc/js/resourceBundleUtils.js file which looks like:
      public String getLogoutURL(HttpServletRequest request)
    return UWCApplicationHelper.getLogoutURL(request);
    }But I can't find where the URL is actually configured.UWCApplicationHelper is in inbuilt java class. The UWCApplicationHelper.getLogoutURL java function returns:
    <current URL context>/base/UWCMain?op=logoutSo for example if UWC is deployed to http://myserver.domain.com/uwc you would get a logout URL of:
    http://myserver.domain.com/uwc/base/UWCMain?op=logoutRegards,
    Shane.

  • Sharepoint Workflow - change URL Path for inside and mobile device email access

    I have a workflow that work perfect when accessing from a desktop.  An email is sent with a link to the item,
    [%Workflow Context:Current Item URL%].  The real address is http://sql/layouts/.......
    When the user tries to click on the link in the email from a mobile device, it doesn't work.
    If I change the mobile device to http://50.xx.xxx.xxx/layouts... it works fine!  (50.xx.xxx.xxx is the port open on our firewall to access SharePoint)
    How can I add a separate link in my workflow email so that users can access the SharePoint task list item from a mobile device?
    I was thinking of having a link for the inside, http://sql... and a link for the mobile device, http://50.xxx.xxx.xxx/...
    Thank you!

    List item URLs are basically a URL to the list item using the item Id. In this case 159 is the item id. The URL represents a downloadable resource like a file in a document library. However in a document library you would get the name of the file plus
    it's extension. For example Contract.pdf. The .000 represents the file extension for the list item URL. If you typed in your URL in the browser to servername/list name/159_.000 you would be prompted to save the file (list item). You can save it to your local
    file system and it will be a file called 159_.000. However the file will be empty since a list item does not contain any binary content. You will have to some how modify the workflow to replace the servername/list name/159._000 to use servername/lists/list
    name/dispform.aspx?id=159. This URL will display the view form for the list item.
    Blog | SharePoint Field Notes Dev Tools |
    SPFastDeploy | SPRemoteAPIExplorer

  • How to set Alias name for URL or change  URL..

    Hi:
    I am using Apache Tomcat as web server, it contains multiple web applications.
    Url for one of this application is, e.g. http://localhost:8080/myapplication. This particular url work fine.
    But i want to use only mypage word instead of all the above url.
    So how to set or map this?
    Thank You,
    Anup Desai.

    Thank you.
    I tried to set the displayname (using setPersonal function)
    Still its not working.
    I feel it is because during authentication we give the login name (which is taken as the display name).
    Is there any way to change without touching configuration level properties in exchange server 2007.
    thanks in advance

  • Element not found when trying to change url for httpstunnel

    We use DirectAccess 2012 and Windows 7 is able connect via DirectAccess
    Netsh dns show state
    shows me that I have httpstunnel adapter with a url 
    According to the following article I should be able to change that url of the httpstunnel which we use for DirectAccess
    https://technet.microsoft.com/en-us/library/dd941590%28v=ws.10%29.aspx#BKMK_4
    However, when I use the following command 
    netsh interface httpstunnel set interface https://something.com:443/IPHTTPS none
    I get the error "Element not found"
    What am I doing wrong here?

    Hi Mister lks,
    Regarding to your question, I’d suggest that we post at Direct Access, UAG and IAG forum. There you can get more effective suggestion by other experts who familiar with Direct Access. Your understanding is highly appreciated.
    https://social.technet.microsoft.com/Forums/forefront/en-US/home?forum=forefrontedgeiag
    Regards,
    D. Wu
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact [email protected]

Maybe you are looking for

  • How can I add a new iTunes account without losing all my music on my iPhone?

    Currently, all of my family's purchases are through my wife's iTunes account.  As such, both of our iPhones are synced with iTunes through that account.  I would like to add an account just for me, but I also don't want to lose all of the music we've

  • Don't want user create new item via VA02

    Hi experts: If I don't want user create new item in sales order via VA02, how can I do it ?? Thanks Shwan

  • 0GLACCEXT Text Datasource

    Dear Gurus, I'm in the process of loading Text Datasource for  Info Objects "0GLACCEXT" , I'm not sure which datasource to select , while going through forums , I've used  the DataSource "0GL_ACCOUNT_TEXT" to load the text data into "0GLACCEXT". Is t

  • IPad2 typing by itself

    My iPad2 (over a year old now) has started acting up. It types by itself or sometimes opens websites randomly when I am in Safari. I backed it up on iTunes and reset the iPad2. That did not help. I then upgraded to iOS6 and that didnt help either. An

  • Cannot print wirelessly USB h/p Officejet 5610 connected to Airport Express

    my iBook G4 is upgraded to Tiger v10.4.11. Can do successful printing tethered to USB printer. Want to print wirelessly. AirPort is active, indicator light is solid green. USB printer is plugged into AirPort Express. I clicked file, then print, then