1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
|
// getServletConnection
private URLConnection getServletConnection()
throws MalformedURLException, IOException, UnavailableServiceException {
BasicService bs;
bs = (BasicService) ServiceManager.lookup("javax.jnlp.BasicService");
// Connection zum Servlet öffnen
URL urlServlet = new URL(bs.getCodeBase(), "Controleur"); // echo c le nom en fait dans http://localhost:8080/echo
URLConnection con = urlServlet.openConnection();
con.setDoInput(true);
con.setDoOutput(true);
con.setUseCaches(false);
con.setRequestProperty(
"Content-Type",
"application/x-java-serialized-object");
return con;
}
public void actionPerformed(ActionEvent e)
{
Object source = e.getSource();
connexion.setText("Action");
// récupérer identifiant et password et identifier l'utilisateur, vers controleur
if(source==seConnecter)
{
try {
// permet de récupérer les informations du jnlp
BasicService bs = (BasicService) ServiceManager.lookup("javax.jnlp.BasicService");
URLConnection con = getServletConnection();
OutputStream os = con.getOutputStream();
connexion.setText("se connecter");
ObjectOutputStream oos = new ObjectOutputStream(os);
Connexion connex = new Connexion(this.identifiant.getText(),this.password.getText());
oos.writeObject(connex);
//bw.write("SeConnecter");
//bw.flush();
//bw.close();
oos.flush();
os.close();
oos.close();
} catch (UnavailableServiceException e1) {
e1.printStackTrace();
} catch (MalformedURLException e2) {
e2.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
}
} |
Partager