Welcome to Dream.In.Code
Become a Java Expert!

Join 150,381 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,238 people online right now. Registration is fast and FREE... Join Now!




HTML form in java?

 
Reply to this topicStart new topic

HTML form in java?

nila
27 Jan, 2008 - 10:32 PM
Post #1

D.I.C Head
**

Joined: 5 Jan, 2008
Posts: 128

Hi,
I want to display the output in an HTML form instead of displaying in terminal.The following code Compiles and run well.
CODE


import org.asteriskjava.live.AsteriskServer;
import org.asteriskjava.live.AsteriskChannel;
import org.asteriskjava.live.AsteriskQueue;
import org.asteriskjava.live.MeetMeRoom;
import org.asteriskjava.live.DefaultAsteriskServer;
import org.asteriskjava.live.ManagerCommunicationException;
public class HelloLive
{
    private AsteriskServer asteriskServer;
    public HelloLive()
    {
        asteriskServer = new DefaultAsteriskServer("localhost", "manager", "pa55w0rd");
    }
    public void run() throws ManagerCommunicationException
    {
        for (AsteriskChannel asteriskChannel : asteriskServer.getChannels())
        {
            System.out.println(asteriskChannel);
        }
        for (AsteriskQueue asteriskQueue : asteriskServer.getQueues())
        {
            System.out.println(asteriskQueue);
        }
        for (MeetMeRoom meetMeRoom : asteriskServer.getMeetMeRooms())
        {
            System.out.println(meetMeRoom);
        }
    }
    public static void main(String[] args) throws Exception
    {
        HelloLive helloLive = new HelloLive();
        helloLive.run();
    }
}

If i run this program,I am getting the output in a terminal.Instead of that I need to display the output in an html form.Is it possible?if yes, please help me to do.The output displayed in the terminal is:
QUOTE

Jan 28, 2008 11:12:58 AM org.asteriskjava.manager.internal.ManagerConnectionImpl connect
INFO: Connecting to localhost:5038
Jan 28, 2008 11:12:58 AM org.asteriskjava.manager.internal.ManagerConnectionImpl setProtocolIdentifier
INFO: Connected via Asterisk Call Manager/1.0
Jan 28, 2008 11:12:58 AM org.asteriskjava.manager.internal.ManagerConnectionImpl doLogin
INFO: Successfully logged in
Jan 28, 2008 11:12:59 AM org.asteriskjava.manager.internal.ManagerConnectionImpl doLogin
INFO: Determined Asterisk version: Asterisk 1.2
Jan 28, 2008 11:12:59 AM org.asteriskjava.live.internal.ChannelManager handleStatusEvent
INFO: Adding new channel SIP/outbound-08dbb658
Jan 28, 2008 11:12:59 AM org.asteriskjava.live.internal.ChannelManager handleStatusEvent
INFO: Adding new channel SIP/5101-08db8628
Jan 28, 2008 11:12:59 AM org.asteriskjava.live.internal.AsteriskServerImpl initializeIfNeeded
INFO: Initializing done
AsteriskChannel[id='1201498975.8',name='SIP/5101-08db8628',callerId='"5101" <5101>',state='RING',account='null',dateOfCreation=Mon Jan 28 11:12:55 IST 2008,dialedChannel=null,dialingChannel=null,linkedChannel=null]
AsteriskChannel[id='1201498975.9',name='SIP/outbound-08dbb658',callerId='<12127773456>',state='DOWN',account='null',dateOfCreation=Mon Jan 28 11:12:59 IST 2008,dialedChannel=null,dialingChannel=null,linkedChannel=null]
Jan 28, 2008 11:13:05 AM org.asteriskjava.live.internal.ChannelManager handleLinkEvent
INFO: Linking channels SIP/5101-08db8628 and SIP/outbound-08dbb658
Jan 28, 2008 11:13:11 AM org.asteriskjava.live.internal.ChannelManager handleUnlinkEvent
INFO: Unlinking channels SIP/5101-08db8628 and SIP/outbound-08dbb658
Jan 28, 2008 11:13:11 AM org.asteriskjava.live.internal.ChannelManager handleHangupEvent
INFO: Removing channel SIP/outbound-08dbb658 due to hangup (NORMAL)
Jan 28, 2008 11:13:11 AM org.asteriskjava.live.internal.ChannelManager handleHangupEvent
INFO: Removing channel SIP/5101-08db8628 due to hangup (NORMAL)
.

Thanks.
User is offlineProfile CardPM
+Quote Post

1lacca
RE: HTML Form In Java?
28 Jan, 2008 - 12:33 AM
Post #2

code.rascal
Group Icon

Joined: 11 Aug, 2005
Posts: 3,822



Thanked: 12 times
My Contributions
Simply output the info into an HTML file.
If you want to access it via HTTP, then put it into a directory that is under a webserver.
you could also write a servlet, but that might be overkill.
User is offlineProfile CardPM
+Quote Post

nila
RE: HTML Form In Java?
28 Jan, 2008 - 01:34 AM
Post #3

D.I.C Head
**

Joined: 5 Jan, 2008
Posts: 128

Thanks for your reply.I dont want to use servlet.without using servlet or jsp page,could i call the class file of the java file in html page like this?
QUOTE

<html>
<head>
<title>HelloLive</title>
<script LANGUAGE="JavaScript">
document.write("<APPLET CODE='JHelloLive.class' HEIGHT=575 WIDTH=650>");
</Script>
</head>
</html>

and put this html file and the java class file in a folder named Hello and put it into the directory /var/lib/www/html/.After that could i access the page in browser like this?
QUOTE

is this method correct?if not please guide me how to do?

This post has been edited by nila: 28 Jan, 2008 - 01:35 AM
User is offlineProfile CardPM
+Quote Post

1lacca
RE: HTML Form In Java?
28 Jan, 2008 - 01:47 AM
Post #4

code.rascal
Group Icon

Joined: 11 Aug, 2005
Posts: 3,822



Thanked: 12 times
My Contributions
Yes, it should work fine as well. However you must edit your class so that it extends the (J)Applet class, and to include a GUI where you display the text.

Right now the text would be logged to the standard output that is the Java console by default (so it would not appear on the HTML page).
User is offlineProfile CardPM
+Quote Post

nila
RE: HTML Form In Java?
28 Jan, 2008 - 01:57 AM
Post #5

D.I.C Head
**

Joined: 5 Jan, 2008
Posts: 128

yes.when i tried like this,i got a blank page only.but i dont understand the below:
QUOTE

you must edit your class so that it extends the (J)Applet class, and to include a GUI where you display the text.

please could you explain in brief?
User is offlineProfile CardPM
+Quote Post

1lacca
RE: HTML Form In Java?
28 Jan, 2008 - 04:21 AM
Post #6

code.rascal
Group Icon

Joined: 11 Aug, 2005
Posts: 3,822



Thanked: 12 times
My Contributions
This is a small Applet tutorial

You could modify one of the examples so that you put your text into a JTextField
User is offlineProfile CardPM
+Quote Post

nila
RE: HTML Form In Java?
29 Jan, 2008 - 09:50 PM
Post #7

D.I.C Head
**

Joined: 5 Jan, 2008
Posts: 128

Hi,
As per the idea given by 1lacca ,I had output the file to an html file by running my program like this:
QUOTE

java -cp .:/var/lib/asterisk/agi-bin/asterisk-java-0.3.1.jar HelloLive > /var/www/html/Hello/output.html

Now i got the output in a html page and i am accessing via http by http://localhost/Hello/form.html.
Now my output looks like
QUOTE

ID= 1201670624.0 ; Name= OSS/dsp ; CallerId= 5101; ChannelState= UP ; Date= Wed Jan 30 10:53:44 IST 2008 ; ID= 1201670624.1 ; Name= SIP/outbound-0927fb18 ; CallerId= <12127773456> ; ChannelState= UP ; Date= Wed Jan 30 10:53:51 IST 2008 ; Name/username Host Dyn Nat ACL Port Status 5102/5102 (Unspecified) D 0 Unmonitored 5101/5101 (Unspecified) D 0 Unmonitored outbound/3103412416 64.119.181.135 5060 Unmonitored 3 sip peers [3 online , 0 offline]
.
Now i need to display my output in a proper gui.(ie).I need to put extensions which are active one by one in that html page like the below:
QUOTE

Extension Status ID
5101 busy 1201670624.0
5102 free. 1201670624.1
.I can just print the extension and status by simply printing .Temporarily i have been asked to hardcode the extension numbers .Now i have to match the status with the extension number like if extension is 5101 i have to get the status through program and print it under status and parallel to 5101.now i have used "&nbsp "for space.what should i have to use to go to next line instead of using lot of "&nbsp".
what should i have to do in this following java code?
CODE

public class HelloLive
{
    private AsteriskChannel astchannel;
    private CallerId callerId;
private Extension extension;
private Extension ext;
private AsteriskChannel channel;
private AsteriskChannel link;
    private Date date;
    private ChannelState channelState;
        private AsteriskServer asteriskServer;
    private AsteriskQueue asteriskQueue;
private MeetMeUser user;
//private Voicemailbox voicemailbox;
String command="sip show peers";
    public HelloLive()
    {
            asteriskServer = new DefaultAsteriskServer("localhost", "admin", "1234");
    }

    public void run() throws ManagerCommunicationException
    {
        for (AsteriskChannel asteriskChannel : asteriskServer.getChannels())
        {
String Id=asteriskChannel.getId();
String name=asteriskChannel.getName();
callerId=asteriskChannel.getCallerId();
channelState=asteriskChannel.getState();
date=asteriskChannel.getDateOfCreation();
System.out.println(date);
System.out.println(";");
System.out.println("DialingChannel=");
System.out.println(astchannel);
System.out.println(";");
System.out.println("DialedChannel=");
System.out.println(channel);
System.out.println(";");
}
        for (AsteriskQueue asteriskQueue : asteriskServer.getQueues())
        {
            System.out.println(asteriskQueue);
        }
        for (MeetMeRoom meetMeRoom : asteriskServer.getMeetMeRooms())
        {
            System.out.println(meetMeRoom);
        }
    for (String string : asteriskServer.executeCliCommand(command))
{
    System.out.println(string);
}
   }
    public static void main(String[] args) throws Exception
    {
        HelloLive helloLive = new HelloLive();
        helloLive.run();    }
}

please help me to do this.

This post has been edited by nila: 30 Jan, 2008 - 12:40 AM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 04:09PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month