How do i make http connection  from an applet to  a servlet

i am not able to make a http connection from the applet to servlet
my code for servlet is as follows
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class newDatabaseServlet extends HttpServlet {
//      Connection con;
// Statement stmt;
     public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
          resp.setContentType("text/content");
          System.out.println("megha");
          String mthd[] = req.getParameterValues("event");
          System.out.println(mthd.length);
          System.out.println(mthd);
          System.out.println(req.getQueryString());
          // System.out.println("megha");
PrintWriter fw = new PrintWriter(new FileOutputStream(new File("e:/JRun/servers/default/default-app/mycontent.txt")));
String s = "this text comes from servlet";
fw.print(s);
fw.flush();
          if(mthd[0].equalsIgnoreCase("callEditor")) {
               openEditor(req,resp);
public void openEditor(HttpServletRequest req, HttpServletResponse resp) {
     /* try {
          Class.forName("oracle.jdbc.driver.OracleDriver");
     con = DriverManager.getConnection("jdbc:oracle:thin:@pc6:1521:oradba","test","test");
     catch(Exception e) {
          e.printStackTrace();
          try {
               resp.sendRedirect("/RunApp1.html");
          catch(IOException e) {
               e.printStackTrace();
/*try {
     Class.forName("oracle.jdbc.driver.OracleDriver");
con = DriverManager.getConnection("jdbc:oracle:thin:@pc6:1521:oradba","test","test");
     catch(Exception e) {
     e.printStackTrace();
     resp.setContentType("text/html");
     PrintWriter output = resp.getWriter();
     try {
stmt = con.createStatement();
String strContent = "select * from edTable where newsid = 2";
ResultSet rs = stmt.executeQuery(strContent);
if(rs.next()) {
               String newsText = rs.getString(2);
/* StringBuffer buf = new StringBuffer();
               buf.append("<B>servlet</B>");
               try {
               resp.sendRedirect("RunApp");
          catch(IOException e) {
               e.printStackTrace();
//               output.println(buf.toString());
//          output.close();
my code for applet is
import javax.swing.*;
import java.awt.event.*;
import java.net.*;
import java.io.*;
import java.awt.*;
import javax.swing.text.*;
import javax.swing.text.html.*;
public class EdApplet extends JApplet {
public void init() {
     Container c;
     c = getContentPane();
JPanel but = new JPanel();
c.add(but,BorderLayout.NORTH);
final JEditorPane je = new JEditorPane();
JScrollPane jsp = new JScrollPane(je);
HTMLEditorKit ht = new HTMLEditorKit();
je.setEditorKit(ht);
je.setEditable(true);
HTMLDocument mdoc = (HTMLDocument)ht.createDefaultDocument();
StyleSheet mcontext =mdoc.getStyleSheet();
je.setDocument(mdoc);
c.add(jsp,BorderLayout.CENTER);
JPanel bot = new JPanel();
c.add(bot,BorderLayout.SOUTH);
JButton save = new JButton("save");
but.add(save);
String str = getInitialText();
     je.setText(str);
     String servletUrl="http://pc7:8100/servlet/newDatabaseServlet";
try{
               URL servletURL = new URL(servletUrl);
               URLConnection servletConnection = servletURL.openConnection();
          servletConnection.setRequestProperty("event","saveText");
          servletConnection.setDoOutput(true);
          servletConnection.setUseCaches(false);
     catch(Exception e) {
//          je.setText(e.printStackTrace());
     ActionListener lst = new ActionListener() {
          public void actionPerformed(ActionEvent ae) {
               String save = je.getText();
               saveText(save,je);
     save.addActionListener(lst);
//je.setText("<B>this</B>");
//URLConnection servletConnection = null;
/* try {
          String servletUrl="http://pc7:8100/servlet/newDatabaseServlet";
          URL myUrl = new URL(servletUrl);
          servletConnection = myUrl.openConnection();
          servletConnection.setDoOutput(true);
          servletConnection.setUseCaches(false);
     /*     BufferedReader br = new BufferedReader(new InputStreamReader(servletConnection.getInputStream()));
String t = br.readLine();
je.setText(t);
     catch(Exception e) {
          e.printStackTrace();
/* ActionListener lst = new ActionListener() {
          public void actionPerformed(ActionEvent ae) {
               BufferedReader br = new BufferedReader(new InputStreamReader(servletConnection.getInputStream()));
               String t = br.readLine();
je.setText(t);
click.addActionListener(lst);
/*void String changeText(UrlConnection con) {
BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream));
String t = br.readLine();
return t;
public String getInitialText()
     //String me = null;
     URLConnection textConnection = null;
     StringBuffer sb = new StringBuffer();
     try {
               String textUrl="http://pc7:8100/mycontent.txt";
               URL myUrl = new URL(textUrl);
               textConnection = myUrl.openConnection();
               textConnection.setDoInput(true);
               textConnection.setUseCaches(false);
               BufferedReader br = new BufferedReader(new InputStreamReader(textConnection.getInputStream()));
               // me = (String)servletConnection.getContent();
               String s = null;
               while((s = br.readLine())!=null) {
                    sb.append(s);
          catch(Exception e) {
                         e.printStackTrace();
               return sb.toString();
     public void saveText(String saveStr,JEditorPane je) {
          //String saveStr = je.getText();
          //String servletUrl="http://pc7:8100/servlet/newDatabaseServlet?event='saveText'&newsid='2'";
          //String servletGet="http://pc7:8100/servlet/newDatabaseServlet";
          String servletUrl="http://pc7:8100/servlet/newDatabaseServlet";
          //String servletUrl = servletGet + "?"
          //     + URLEncoder.encode("event") + "="
     // + URLEncoder.encode("saveText");
//     je.setText(servletUrl);
          try {
          URL servletURL = new URL(servletUrl);
          URLConnection servletConnection = servletURL.openConnection();
     //     servletConnection.setRequestProperty("event","saveText");
     servletConnection.setRequestProperty(
     "User-Agent","Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
          //System.out.println("from applet");
          servletConnection.setDoOutput(true);
          servletConnection.setUseCaches(false);
          //Propertiew prop = new Properties();
     //     prop.put("event","saveText");
          PrintStream out = new PrintStream(servletConnection.getOutputStream());
out.println("event");
out.close();
     catch(IOException e) {
          je.setText(e.toString());
kindly tell me what is the error
what is the best method of doing this
thanking u in anticipation
megha sood

omg O_o
We cannot debug your code, but:
Did you try the servlet directly from your browser? Does it work?
Best regards from Germany,
r.v.

Similar Messages

  • How to establish an Https connection from a html client

    Hi! I�m totally new to Java so my question is rather"stupid". I have an html page that sends a post to a servlet
    <form name="form" action="servlet/ServletLogOn" method="post">
    I want to establish an https connection between the client and the servlet. How is it?
    Thanks in advance.

    Ignore the previous poster's reply - he was obviously mislead by my original post re: JSSE.
    How you install an SSL certificate on your webserver is completely dependent on the webserver you are using. Ususally there is some functionality for doing this from the administrative interface - usually involves pasting some text from the CA's (certificate authority, e.g. Verisign) site into a text box and designating a port number for SSL traffic (use 443, it's internet standard). I've actually only done this for Netscape Enterprise Server - you may want to find a forum for users of your webserver to ask for specifics.

  • How to transfer the http request from applet to servlet/jsp

    I use the JTree component to create a navigation of a website,but i don't
    know how to connect the tree's nodes with the jsp/servlet.
    I mean how to transfer the http request from the applet to a jsp.
    I use the "<frameset>" mark which will divide the web browse into 2 blocks.
    The left side is Applet,and the right side is the linked jsp page.
    what I say is as the weblogic console layout.
    who can help me!!!
    Thank You!

    I use the JTree component to create a navigation of a website,but i don't
    know how to connect the tree's nodes with the jsp/servlet.
    I mean how to transfer the http request from the applet to a jsp.
    I use the "<frameset>" mark which will divide the web browse into 2 blocks.
    The left side is Applet,and the right side is the linked jsp page.
    what I say is as the weblogic console layout.
    who can help me!!!
    Thank You!

  • HTTPS connection from servlet to another webserver

    Hi,
    We want to make a https connection from a servlet in weblogic server to another
    web server (not necessarily weblogic). We also need dual authentication. But whenever
    we use URL.openConnection(), it always returns us weblogic's internal https and
    SSL implementation. Since weblogic has no documentation about how to use these
    internal classes, such as how to set trusted server certificate, and how to set
    client certificate (servlet is a client of another web server). We want to use
    jsse, after setting JSSE required system properties, I still get a weblogic's
    httpsURLConnection. Can any of you tell me how to resolve this issue?
    Thanks.
    Xinshi

    Yeah, I'm using JSSE now. Here is what I did:
    Security.addProvider(new com.sun.net.ssl.internal.ssl.Provide());
    Provider prov = new SimpleSecureProvider();
    prov.setProperty("SecureRandom.efficient", "test.EfficientSecureRandom");
    Security.insertProviderAt(prov, 1);
    You don't really need the provider stuff to get the example working. I use it
    to get around a quick in JSSE where the random number generator takes 15-30 seconds
    to generate a random sequence at start up.
    SimpleSecureProvider looks like this:
    public class SimpleSecureProvider extends Provider
    public SimpleSecureProvider()
    super("SimpleSecureProvider-", 1.0, "Hack to enable more efficient random
    seed generator");
    test.EfficientSecureRandom is bascially an exact copy of Sun's SecureRandom.java
    with the only difference that I used my own random number generator.
    Anyway, rest of the code you need looks like this:
    URL url= new URL("htps://someplace.com");
    URLConnection sconnection = url.openConnection();
    Do whatever.
    I also stored jcert.jar, jnet.jar, jsse.jar in /usr/java/jdk1.3/lib/ext
    I think that is everything.
    I just noticed that service pack 9 has a security example that does not require
    all these jsse hacks. I'm trying to get it to work, but not having much luck.
    Anybody got this working right?
    "Jayesh Patel" <[email protected]> wrote:
    See if this works,
    1. Add the 'j2ee.jar' to CALSSPATH in weblogic startup script.
    2. Set the property SSLHandlerEnabled flase in config.xml
    3. Add the following property permission to the
    weblogic.policy' file under a 'grant' directive
    for all codebases (bottom): 'permission java.security.AllPermission'
    4. Use the following bit of source code to create an https connection:
    import com.sun.net.ssl.*; ....
    com.sun.net.ssl.HttpsURLConnection connection;
    System.setProperty ("java.protocol.handler.pkgs",
    "com.sun.net.ssl.internal.www.protocol");
    java.security.Security.addProvider(new
    com.sun.net.ssl.internal.ssl.Provider() );
    URL url = new URL( "https", hostname, query );
    -Jayesh
    connection = (com.sun.net.ssl.HttpsURLConnection )url.openConnection(
    "Xinshi Sha" <[email protected]> wrote in message
    news:[email protected]...
    Hi,
    We want to make a https connection from a servlet in weblogic serverto
    another
    web server (not necessarily weblogic). We also need dual authentication.But whenever
    we use URL.openConnection(), it always returns us weblogic's internalhttps and
    SSL implementation. Since weblogic has no documentation about how
    to
    use
    these
    internal classes, such as how to set trusted server certificate, andhow
    to set
    client certificate (servlet is a client of another web server). Wewant to
    use
    jsse, after setting JSSE required system properties, I still get aweblogic's
    httpsURLConnection. Can any of you tell me how to resolve this issue?
    Thanks.
    Xinshi

  • HTTPS connection from portal to external webserver

    Hi,
    I am looking for a way to open a HTTPS connection from portal server to an external webserver. According to <a href="http://help.sap.com/saphelp_nw04/helpdata/en/e2/71c83edf72e16be10000000a114084/content.htm">SAP</a> the code should look like
    KeyStore keystoreCAs = ...
    SecureConnectionFactory factory = new SecureConnectionFactory(keystoreCAs, null);
    HttpURLConnection con = factory.createURLConnection("https://www.mycompany.com");
    Does not look difficult, <b>but how do I create the keystore object</b>? The keystore object should somehow be connected to the portal server's keystore which manages the certificates of trusted Certificate Authorities.
    Any ideas?
    Regards,
    Martin

    Hi,
    meanwhile I solved the problem by my own. The solution slightly simplified is given below.
    javax.naming.InitialContext ctx = new javax.naming.InitialContext();
    java.lang.Object o = ctx.lookup("keystore");          
    com.sap.engine.services.keystore.interfaces.KeystoreManagerWrapper_Stub manager = (com.sap.engine.services.keystore.interfaces.KeystoreManagerWrapper_Stub) o;
    java.security.KeyStore keystoreCAs = manager.getKeystore("TrustedCAs");     
    com.sap.security.core.server.https.SecureConnectionFactory factory = new SecureConnectionFactory(keystoreCAs, null);
    java.net.HttpURLConnection con = factory.createURLConnection("https://www.mycompany.com");
    For connecting via a proxy the host name and port number of the proxy have to be set as System properties using "https.proxyHost" and "https.proxyPort".
    java.util.Properties systemSettings = System.getProperties();
              systemSettings.put("proxySet", "true");
              systemSettings.put("https.proxyHost","192.168.0.1") ;
              systemSettings.put("https.proxyPort", "80") ;
    Additionally you have to make sure that the server's certificate is issued by a trusted Certification Authority (Must have an entry in your Keystore "TrustedCAs"). To verify this use the Visual Administrator and view service "Key Storage".
    Regards,
    Martin

  • How do I make a connection to SQL Server Express using SQL Developer 1.5.3?

    How do I make a connection to SQL Server Express using SQL Developer 1.5.3, if it's possible at all?
    Also, I received a SQL Server dump file of some sort. Is there any way to read this file in SQL Developer and migrate the db to Oracle? Unfortunately I don't have raw DDL and DML for this database--just some sort of a binary dump file from SQL Server.
    Thanks.
    Dana

    Are you using SQL Developer 1.5.3 or 1.5.4?
    If using an older version (i.e. 1.5.3), then you'll have to add a DLL to your environment. This is [ntlauth.dll].
    If you don't find this DLL in your SQL Developer directory, then obtain the JDBC SQL SERVER Pluggin (jtds-1.2.2-dist.zip) from:
    http://sourceforge.net/project/showfiles.php?group_id=33291&package_id=25350
    Copy the ntlmauth.dll in the ...\\...\ide\lib directory (no need to register it).
    Note: this approach should work if using DQL Developer 1.5.3 and SQL Server Express 2008
    Regards,
    M. R.

  • HTTPS connection from database

    Hi all,
    I have to implement https connection from a database with a Web server which requests a client certificate. I have the certificate in the wallet, but UTL_HTTP does not send it to the Web server.
    So, is there any way to connect to a Web server which requires a client certificate?

    Could you explain how transport protocol influences certificate exchange during SSL session?

  • My iPod Touch is connected to my house internet and every few hours, it doesn't work so I have to shut it off and turn it back on which makes my iPod slower, how do I make it connect the whole time?

    My iPod Touch is connected to my house internet and every few hours, it doesn't work so I have to shut it off and turn it back on which makes my iPod slower, how do I make it connect the whole time?

    Device Not Recognised
    For PC
    http://support.apple.com/kb/TS1538
    For Mac
    http://support.apple.com/kb/ts1591

  • How can I make a backup from my Macbook Pro?

    How can I make a backup from my Macbook Pro?

    Basic Backup
    For some people Time Machine will be more than adequate. Time Machine is part of OS X. There are two components:
    1. A Time Machine preferences panel as part of System Preferences;
    2. A Time Machine application located in the Applications folder. It is
         used to manage backups and to restore backups. Time Machine
         requires a backup drive that is at least twice the capacity of the
         drive being backed up.
    See Mac Basics- Time Machine. Please visit Pondini's Time Machine FAQ for help with all things Time Machine.
    Alternatively, get an external drive at least equal in size to the internal hard drive and make (and maintain) a bootable clone/backup. You can make a bootable clone using the Restore option of Disk Utility. You can also make and maintain clones with good backup software. My personal recommendations are (order is not significant):
      1. Carbon Copy Cloner
      2. Get Backup
      3. Deja Vu
      4. SuperDuper!
      5. Synk Pro
      6. Tri-Backup
    Visit The XLab FAQs and read the FAQ on backup and restore.  Also read How to Back Up and Restore Your Files. For help with using Time Machine visit Pondini's Time Machine FAQ for help with all things Time Machine.
    Although you can buy a complete external drive system, you can also put one together if you are so inclined.  It's relatively easy and only requires a Phillips head screwdriver (typically.)  You can purchase hard drives separately.  This gives you an opportunity to shop for the best prices on a hard drive of your choice.  Reliable brands include Seagate, Hitachi, Western Digital, Toshiba, and Fujitsu.  You can find reviews and benchmarks on many drives at Storage Review.
    Enclosures for FireWire and USB are readily available.  You can find only FireWire enclosures, only USB enclosures, and enclosures that feature multiple ports.  I would stress getting enclosures that use the Oxford chipsets especially for Firewire drives (911, 921, 922, for example.)  You can find enclosures at places such as;
      1. Cool Drives
      2. OWC
      3. WiebeTech
      4. Firewire Direct
      5. California Drives
      6. NewEgg
    All you need do is remove a case cover, mount the hard drive in the enclosure and connect the cables, then re-attach the case cover.  Usually the only tool required is a small or medium Phillips screwdriver.

  • Can't make a connection from JDeveloper 10g (9.0.5.0) to WebLogic 8.1

    I can't make a connection from JDeveloper 10g (9.0.5.0.0) to WebLogic 8.1
    When I click "Test connection" JDeveloper 10g writes the following:
    Cannot instantiate class: weblogic.jndi.WLInitialContextFactory
    Have somebody ever established a connection from JDeveloper 10g (9.0.5.0) to WebLogic 8.1? How to do this?

    It connects successfully now. Thank you for the information.
    But it does nothing when I try to deploy my J2EE application.
    I right-click on Resources -> application.deploy, choose "Deploy to" -> my connection. It starts to do something obscure.
    Then I go to the WebLogic console and it shows that there is no my application.

  • How do i make the imessage from my macbook be sent from my number and

    how do i make the imessage from my macbook be sent from my number and not from my e mail address?

    MacBook Series Forums
    https://discussions.apple.com/community/notebooks?view=discussions
    http://www.apple.com/support/macbookpro
    Mac OS X Forum
    https://discussions.apple.com/community/mac_os?view=discussions
    This forum deals with a desktop/tower 65lb Mac Pro
    http://www.apple.com/support/macpro
    http://www.apple.com/support/iphone 
    http://www.apple.com/support/icloud/

  • How could I make a connection to XE using Jdeveloper and JSF?

    Hello, I want to develop an application that must interact with a Oracle Database Express Edition. How could I make a connection to it and display, for example, a table from the database in a JSP using JSF in Jdeveloper.

    Hi ,
    I have installed Jdeveloper 10.1.3.1.0 and Oracle database Express edition 10g on the same machine.I want to connect to the database from Jdeveloper but i get the message "The Network Adapter could not establish the connection" , when i test the connection. The listener is running and am able to connect to database using SQL Plus.
    I have tried various methods like giving the ipaddress and giving the URL, looking at the JDBC configuration wizard given in the documentation , but of no use .. can anyone please suggest me how to connect??

  • How can I make a screensaver from a Java program?

    Hi!
    I've made a Java program works as a screensaver, and I've grouped all files into a jar file. How can I make a screensaver from this jar file?
    Thanks.

    check https://jdic.dev.java.net/documentation/incubator/screensaver/
    - I think it's still in development, but it's something...

  • Opening an https connection from within a Servlet.

    I am having problems trying to establish an HTTPS connection to a servlet from within a different servlet.
    I get the java.net.MalformedURLException: unknown protocol: https. SSL is setup for the web server. Direct connections from the browser to a servlet work fine with SSL, but a connection from one servlet to another servlet fails. I'm stumped. Is there a separate SSL install/configuration required for the servlet engine? Could anyone explain?

    When you set up SSL enabled web server, you should be getting a trust cert file that knows the hand shake protocol to talk to that server. Once you have that file, you can load that file from that servlet using System.load and then you would be able to talk to anything that runs on that SSL enabled Web server.
    Also you must have JSSE jar files installed in your system .
    Check out this url:
    http://java.sun.com/products/jsse/INSTALL.html
    Let me know if you still have problems

  • How can I make a call from iPad

    How can I make a call from IPad

    Oh, you have to get the iPhone app.
    Seriously, though .... you are aware that it's not a telephone, right? Any calls you make will be using VOIP and any of the apps and/or services (Skype, Google Talk, etc., etc.) which support that. Some of those are US-only, all have various restrictions and cost structures.

Maybe you are looking for

  • Limit number of rows from wildcard expansion- DRG-51030

    We use CONTEXT iindex in 11g to search on a text DB column, "Name". This is used in a UI to show autosuggest list of 25 matching names. When the end user types an 'a' we want to show a list of the first 25 names that contain an 'a'. We hit the issue

  • Block by QM for purchase order but also for scheduling agreement

    Dear. Using QM info record I can block purchase order creation for a material/vendor with error message 06883. I need to block also scheduling agreement creation but during ME31L for the same material/vendor the system send only warning message 06883

  • Title and JFrame size

    hello, My problem is the next one : -when I use the pack() method on my JFrame it doesn't use the title bar size...so the title is often cut. -when I use the frame.setSize() method, the size of the frame is dependant of the system and the computer...

  • Is Oracle E-Business Suite 12.1.3 certified with Oracle Application Server

    Is Oracle E-Business Suite 12.1.3 certified with Oracle Application Server Single Signon 10.1.4.3.0 on Linux x86-64 SLES 11 (not SLES 10) ? I do see Oracle Application Server Single Signon 10.1.4.3.0 listed on the certification matrix for R12.1.3 , h

  • Panasonic GF1 horrible color cast

    It seems that Aperture has some serious issues with a magenta color cast when converting GF1 RAW files. It's not so apparent with 100-200 ISO (but still there, especially whith large white balance shifts) images but once you get to ISO 800 the images