473,425 Members | 1,771 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,425 software developers and data experts.

How to forward to or run a Java Swing application from JSP?

Hello,

I have a Java Swing application that I would like to be able to forward to or to run it - sorry, I am not sure if I am using the right term - from a JSP page. And I would like for my Java application to run in the same browser that my JSP page ran.

My JSP code is like this :

Expand|Select|Wrap|Line Numbers
  1. <%@ page language ="java" import="java.sql.*" %>
  2. <html>
  3. <body bgcolor="pink">
  4. <form name="f1" method="post">
  5. <table>
  6. <tr>
  7. <td>User Name</td><td><input type="text" name="t1" ></td>
  8. </tr>
  9. <td>Password</td>
  10. <td><input type=""password"" name="t2"></td>
  11. </tr>
  12. <tr>
  13. <td></td>
  14. <td><input type="submit" name="b1" value="LogIn"></td>
  15. </tr>
  16. </table>
  17. <%
  18. String user=request.getParameter("t1");
  19. String pass=request.getParameter("t2");
  20.  
  21.         Connection con = null;
  22.  
  23.      try {
  24.         Class.forName("net.sourceforge.jtds.jdbc.Driver");
  25.      } catch (ClassNotFoundException cnfe) { 
  26.         System.out.println("cannot load Driver");
  27.      }
  28.      try{
  29.         con=DriverManager.getConnection("jdbc:jtds:sqlserver://nnn.nn.nn.nnn:50305", "akino", "abc123");
  30.         Statement st=con.createStatement();
  31.         ResultSet rs=st.executeQuery("select LName from login where LName = '" + user + "'");
  32.         while (rs.next())
  33.         {
  34.            %>
  35.            <hi>login ok</h1> 
  36.            <jsp:forward page="LoginSuccess.jsp"/>
  37.            <%
  38.         }
  39.      }catch(Exception e1) {}
  40.      %>
  41. </form>
  42. </body>
  43. </html>
  44.  
With this code, I can forward to "LoginSuccess.jsp". But
when I tried :

Expand|Select|Wrap|Line Numbers
  1. <%@ page language ="java" import="java.sql.*" %>
  2. <html>
  3. <body bgcolor="pink">
  4. <form name="f1" method="post">
  5. <table>
  6. <tr>
  7. <td>User Name</td><td><input type="text" name="t1" ></td>
  8. </tr>
  9. <td>Password</td>
  10. <td><input type=""password"" name="t2"></td>
  11. </tr>
  12. <tr>
  13. <td></td>
  14. <td><input type="submit" name="b1" value="LogIn"></td>
  15. </tr>
  16. </table>
  17. <%
  18. String user=request.getParameter("t1");
  19. String pass=request.getParameter("t2");
  20.  
  21.         Connection con = null;
  22.  
  23.      try {
  24.         Class.forName("net.sourceforge.jtds.jdbc.Driver");
  25.      } catch (ClassNotFoundException cnfe) { 
  26.         System.out.println("cannot load Driver");
  27.      }
  28.      try{
  29.         con=DriverManager.getConnection("jdbc:jtds:sqlserver://nnn.nn.nn.nn:50305", "akino", "abc123");
  30.         Statement st=con.createStatement();
  31.         ResultSet rs=st.executeQuery("select LName from login where LName = '" + user + "'");
  32.         while (rs.next())
  33.         {
  34.        Runtime.getRuntime().exec("java -jar /NetBeansProjects/NumberAddition/dist/NumberAddition.jar")
  35.            %>
  36.            <hi>login ok</h1> 
  37.            <%
  38.         }
  39.      }catch(Exception e1) {}
  40.      %>
  41. </form>
  42. </body>
  43. </html>
  44.  
My Java Swing application ran. But it would display outside the original (JSP page) browser. I wonder if there is a way to make my Java application to run inside my original browser, like when I was forwarding to "LoginSuccess.jsp"?

Thank you and Best Regards,

Akino
Aug 17 '10 #1
3 5694
Oralloy
988 Expert 512MB
Akino,

I think you can do what you want by creating a trival JSP page, then invoking the outside application as part of your current thread of exectution, so it runs under the same servlet server that your JSPs are running in.

The sequence will go something like:

1) Create a StringWriter (s) to catch the application's output.
2) Load the application's main class (c).
3) Use reflection to find the "main" entry point in c, call it "m".
4) Update java.lang.System to replace err and/or out with s.
5) Invoke m.
6) Restore java.lang.System.err and/or .out
7) Dump the accumulated string to your JSPs output stream.
8) Smile and say "What a good boy am I".

Or, if that's too complex, use System.execute to run your program as a background program, and collect its output using a pipe. Then retransmit that output to yoru JSP's data stream.

The second is probably the better solution; the first is just begging for troubles and mischief.

Cheers and Good Luck!
Aug 17 '10 #2
Hello Oralloy,

Thank you so much for your help.

I wonder if you could please tell me if the second solution you gave me would work if I run my JSP page and my Java application on a client side?

Thank you again,

Akino
Aug 18 '10 #3
Oralloy
988 Expert 512MB
Akino,

As far as I know, JSP is a server-side technology.

Your server may be running on your desktop system, but that shouldn't negatively affect anything. Well, unless you've intentionally coded something to interfere with the smooth behaviour of your application.

Anyway, I'm off for the rest of the day. Hopefully if I'm not clear, one of the other folks can help you.

Cheers!
Aug 18 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Scott Khan | last post by:
We have a Java Swing position. Need consultants ASAP. Position : Java Swing XML / SOAP - FX / Brokerage Requirements : Swing - JTrees / Jtables. other swing classes. etc. Java/ J2EE. JDK...
4
by: arivazhaganit | last post by:
hi.. I'm developing an application in java swing , in that If I click a button , that event should open a file like( http://www.google.co.in) in a browser or in mycomputer..... Plz help me
1
by: dumindaj | last post by:
I have problems running my Java Swing application remotely on a Linux machine. The application takes 20/30s to respond to events and painting takes considerable time. This is not a special case...
3
by: dumindaj | last post by:
I have problems running my Java Swing application remotely on a Linux machine. The application takes 20/30s to respond to events and painting takes considerable time. This is not a special case...
5
by: haran | last post by:
Hi, I have developed a project by using java Swings. Now i want to deploy that project into web. If its applet means we can deploy that by using browser. so plz help me to deploy the java swing...
2
by: sezanawa | last post by:
Hi Guys, I am new to java deployment things. Specially for desktop applications. I used to work with J2EE and i did deployment only for web projects. Now i have developed a small desktop...
3
by: itsmichelle | last post by:
This is a very primative code of a java swing calculator. I have assigned all the number buttons and the operator buttons and I can add, subtract, multiply, and divide two numbers together. However,...
8
risk32
by: risk32 | last post by:
Hi all. I have a really confusing problem. I'm using Swing and I'm trying to do a confirmation box : int reply; String message = "Do you want to input another number?"; String title = "Input...
10
by: yeshello54 | last post by:
Hey guys i am pretty new to java swing and need some help. I am developing a simple color chooser program in swing. I have a color panel that is connected to three sliders. red green and blue. but...
2
by: Selva123 | last post by:
Hi All, Greetings. I want to test JAVA SWING application with PERL, do we have any module to do so (like win32::GUI for windows)?. or some third party free tools integrated with PERL? I am...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.