wood burning stoves 2.0*
The moose likes Servlets and the fly likes Open JFrame from servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Open JFrame from servlet" Watch "Open JFrame from servlet" New topic
Author

Open JFrame from servlet

suresh manchikanti
Greenhorn

Joined: May 27, 2011
Posts: 2
Hi,
I am trying open jframe from servlet .Actually jframe object is created but it is not showing jframe.I already written jframeObj.show().
and also tried jframeObj.setVisible(true) .But it is not showing the jframe window.Please give me your valuable suggestion .

Thanks in advance
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60822
    
  65

You cannot mix Swing with servlets. Servlets must generate HTML or other formats suitable for display in a browser.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
suresh manchikanti
Greenhorn

Joined: May 27, 2011
Posts: 2
Hi,
This is my source code.



import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class NewServlet extends HttpServlet {

protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try {
out.write("Welcome");
NewJFrame o=new NewJFrame();
o.show();
// NewJFrame obj = new NewJFrame();
// out.write("JFrame name="+obj.getName());
// obj.setLocation(500, 500);
// obj.show();
// obj.setVisible(true);

class NewJFrame extends javax.swing.JFrame {

/** Creates new form NewJFrame */
public NewJFrame() {
initComponents();
}

private void initComponents() {

jButton1 = new javax.swing.JButton();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

jButton1.setText("jButton1");

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addGap(150, 150, 150).addComponent(jButton1).addContainerGap(177, Short.MAX_VALUE)));
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup().addContainerGap(166, Short.MAX_VALUE).addComponent(jButton1).addGap(111, 111, 111)));

pack();
}// </editor-fold>
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
// End of variables declaration
}
out.write("******************Welcome");
} finally {
out.close();
}
}
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}

protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
}



Please tell me what are the changes to be made in code to make jframe visible.
When i run this servlet from netbeans IDE ,the jframe is pop uped.But i trying to run from tomcat deployed folder ,jframe is not pop uped.I have seen log also,in that jframe object is created but it is not visible in browser.


Please tell me what are the changes to be made in code to make jframe visible.
When i run this servlet from netbeans IDE ,the jframe is pop uped.But i trying to run from tomcat deployed folder ,jframe is not pop uped.I have seen log also,in that jframe object is created but it is not visible in browser.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60822
    
  65

Did you read my reply?
 
 
subject: Open JFrame from servlet
 
Similar Threads
JFrame one instance
Swing
How to create a new window from a java app
invoke a swing application from servlet
how to refresh the date , without having to restart tomcat