Estou precisando obter o retorno do bloco switch ao executar o Web Start…
resumindo, não estou conseguindo comunicar meu webstart com o banco do lado do servidor…
Criei um projeto web e inseri:
launch.jnlp
<?xml version="1.0" encoding="UTF-8"?>
<jnlp codebase="http://localhost:8080/Alistamento-WEB/" href="launch.jnlp"
spec="1.0+">
<information>
<title>MyGUI</title>
<vendor>Adam English</vendor>
<homepage href="www.google.com"/>
<description>MyGUIapp</description>
<description kind="short">Test to show students</description>
</information>
<resources>
<j2se version="1.6+"/>
<jar eager="true" href="Alistamento-WEBSTART.jar" main="true"/>
<jar href="jasypt-1.7.1.jar"/>
</resources>
<application-desc main-class="alistamento.webstart.FrmLogin2">
</application-desc>
</jnlp>
launch.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Test page for launching the application via JNLP</title>
</head>
<body>
<h3>Test page for launching the application via JNLP</h3>
<a href="launch.jnlp">Launch the application</a>
<!-- Or use the following script element to launch with the Deployment Toolkit -
->
<!-- Open the deployJava.js script to view its documentation -->
<!--
<script src="http://java.com/js/deployJava.js"></script>
<script>
var url="http://[fill in your URL]/launch.jnlp"
deployJava.createWebStartLaunchButton(url, "1.6")
</script>
-->
</body>
</html>
e o jar o webstart que contem o FrmLogin2…
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package alistamento.webstart;
import br.bean.UsuarioFacadeRemote;
import java.util.Properties;
import javax.naming.InitialContext;
import javax.swing.JOptionPane;
/**
*
* @author Usuario
*/
public class FrmLogin2 extends javax.swing.JFrame {
/**
* Creates new form FrmLogin2
*/
public FrmLogin2() {
initComponents();
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jButton1 = new javax.swing.JButton();
jTextField1 = new javax.swing.JTextField();
jPasswordField3 = new javax.swing.JPasswordField();
jLabel2 = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jLabel1.setText("Usuário");
jButton1.setText("Logar");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jTextField1.setName("jTxtUsuario");
jPasswordField3.setName("jPassWordSenha");
jLabel2.setText("Senha");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel1)
.addComponent(jLabel2))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jTextField1)
.addComponent(jPasswordField3, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 105, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton1)
.addGap(76, 76, 76)))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(35, 35, 35)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(23, 23, 23)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(jPasswordField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jButton1)
.addContainerGap(39, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
JOptionPane.showMessageDialog(null,"TESTE OK!");
try {
//USANDO EJB
// Properties props = new Properties();
// props.setProperty(InitialContext.PROVIDER_URL, "10.39.50.179:3700");
//endereço da maquina e a porta. Por padrão a porta a se utilizar é a 1099
Properties props = new Properties();
props.setProperty("java.naming.factory.initial",
"com.sun.enterprise.naming.SerialInitContextFactory");
props.setProperty("java.naming.factory.url.pkgs",
"com.sun.enterprise.naming");
props.setProperty("java.naming.factory.state",
"com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl");
// optional. Defaults to localhost. Only needed if web server is running
// on a different host than the appserver
props.setProperty("org.omg.CORBA.ORBInitialHost", "localhost");
// optional. Defaults to 3700. Only needed if target orb port is not 3700.
props.setProperty("org.omg.CORBA.ORBInitialPort", "3700");
InitialContext ctx = new InitialContext(props); //instancia o InitialContext e prossegue com o lookup em seguida.
// InitialContext ctx = new InitialContext();
UsuarioFacadeRemote usuario = (UsuarioFacadeRemote) ctx.lookup("UsuarioFacade");
setFlagLogin(usuario.validaUsuario(jTextField1.getText(), jPasswordField3.getText()));
switch (getFlagLogin()) {
case 1:
JOptionPane.showMessageDialog(null, "Usuario ok");
break;
case 2:
JOptionPane.showMessageDialog(null, "Login e senha não conferem!");
break;
case 3:
JOptionPane.showMessageDialog(null, "Erro de login e senha duplicados na base de dados, contacte o administrador para solucionar o problema!");
break;
default:
JOptionPane.showMessageDialog(null, "Ocorreu um erro inesperado!");
}
} catch (Exception ex) {
System.out.println(ex);
}
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/*
* Set the Nimbus look and feel
*/
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/*
* If Nimbus (introduced in Java SE 6) is not available, stay with the
* default look and feel. For details see
* http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(FrmLogin2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(FrmLogin2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(FrmLogin2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(FrmLogin2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/*
* Create and display the form
*/
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new FrmLogin2().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JPasswordField jPasswordField3;
private javax.swing.JTextField jTextField1;
// End of variables declaration
private int flagLogin = 0;
/**
* Get the value of flagLogin
*
* @return the value of flagLogin
*/
public int getFlagLogin() {
return flagLogin;
}
/**
* Set the value of flagLogin
*
* @param flagLogin new value of flagLogin
*/
public void setFlagLogin(int flagLogin) {
this.flagLogin = flagLogin;
}
}