-
Apr 4th, 2013, 06:49 PM
#1
Thread Starter
New Member
Calling Java servlets from VB6
I just found out this is easy to do
This isn't a question just wanting to note that it's not only possible but works really well
I setup my Tomcat and can call servlets and pass parameters and get stuff back
I'm using this setup to do some SQL stuff bypassing the need for ODBC and ADO because it's done in JDBC in the Java
And it means I can do DB stuff over the internet. This is a cool feature of VB that you can do
here's a code sample:
Private Function ExecuteSQL(ByVal sSQL As String, ByVal bResultSet As Boolean) As String
Dim http As Object
Dim strURL As String
Dim strPostData As String
Dim strHeader As String
Dim strResponse As String
On Error GoTo Err
Screen.MousePointer = vbHourglass
Set http = CreateObject("WinHttp.WinHttpRequest.5.1")
strPostData = "?Command=" & IIf(bResultSet, "SELECT", "UPDATE") & "&SQL=" & sSQL
strURL = "http://localhost:8080/FirstProject/DBConnector" & strPostData
http.setTimeouts 10000, 10000, 10000, 10000 'For some reason times out sooner than this sometimes
http.Open "POST", strURL, False
http.SetRequestHeader "Content-Type", "application/x-www-form-urlencoded"
http.Send strPostData
strResponse = http.ResponseText
Screen.MousePointer = vbDefault
ExecuteSQL = strResponse
Exit Function
-
Apr 4th, 2013, 07:38 PM
#2
Re: Calling Java servlets from VB6
Actually this is very common and you are not really calling any Java at all. All you are doing is using VB to send an HTTP POST command to a website. When the POST command is processed by the HTTP Web Server it fetches the appropriate processing program; in this case it is DBConnector which is usually a script since most Web Sites don't allow executables.
How do you know that DBConnector is a Java language program be it a script or not.
So, in an indirect way, yes, you could say that you are calling some type of program (whether it is Java or some other language) but in reality you are just setting up the argument list and telling the web server which program to use.
Last edited by jmsrickland; Apr 4th, 2013 at 08:53 PM.
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
-
Apr 5th, 2013, 04:32 AM
#3
Re: Calling Java servlets from VB6
Moved to the General Develop forum.
-
Apr 5th, 2013, 12:12 PM
#4
Re: Calling Java servlets from VB6
It just looks like you are doing a FORM POST, a sort of Web Scraper's notion of how to implement a Web Service.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|