Précédent   Forum des professionnels en informatique > Java > Développement Web en Java > Applets
Applets Vos questions sur les Applets
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 12/10/2011, 11h05   #1
Membre du Club
 
Homme Mathieu
Ingénieur développement logiciels
Inscription : juin 2006
Messages : 154
Détails du profil
Informations personnelles :
Nom : Homme Mathieu
Âge : 28
Localisation : France, Gironde (Aquitaine)

Informations professionnelles :
Activité : Ingénieur développement logiciels
Secteur : High Tech - Éditeur de logiciels

Informations forums :
Inscription : juin 2006
Messages : 154
Points : 50
Points : 50
Par défaut Problème communication applet / servlet (struts)

Bonjour,

J'essaie de faire communiquer mon applet avec une action struts. Le problème c'est que j'ai l'impression que ma servlet n'est jamais appelée car j'ai mis des logger à l'intérieur et je ne retrouve pas les traces...

Voici le code de mon applet:
Code :
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
private URLConnection getServletConnection()
			throws MalformedURLException, IOException {
 
			// Connection servlet
			URL urlServlet = new URL("http://localhost:8080/HelloDMP-web/creationDMP.action");
			URLConnection con = urlServlet.openConnection();
 
			// configuration
			con.setDoInput(true);
			con.setDoOutput(true);
			con.setUseCaches(false);
 
			return con;
		}
 
	public void onSendData() {
		try {
 
			// send data to the servlet
			URLConnection con = getServletConnection();
			OutputStream outstream = con.getOutputStream();
			ObjectOutputStream oos = new ObjectOutputStream(outstream);
			oos.writeObject(new String("1234"));
			oos.flush();
			oos.close();
 
			// receive result from servlet
			InputStream instr = con.getInputStream();
			ObjectInputStream inputFromServlet = new ObjectInputStream(instr);
			String result = (String) inputFromServlet.readObject();
			inputFromServlet.close();
			instr.close();
 
			// show result
			System.out.println("Result servlet: " + result);
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}
Celui de ma servlet:
Code :
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
 
public class CreationDMPAction extends ActionSupport {
 
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
 
	private static Logger log = Logger.getLogger(CreationDMPAction.class);	
 
	private static final String ERROR_SESSION = "error_session";
 
	private UserCarteCps userCarteCps;
 
    private ICpsService cpsService;
 
    public ICpsService getCpsService() {
		return cpsService;
	}
	public void setCpsService(ICpsService cpsService) {
		this.cpsService = cpsService;
	}
 
	public UserCarteCps getUserCarteCps() {
		return userCarteCps;
	}
	public void setUserCarteCps(UserCarteCps userCarteCps) {
		this.userCarteCps = userCarteCps;
	}
 
	/*@TypeConversion(converter = "com.enovation.dmp.util.DateConverter")
    @RequiredFieldValidator(message = "Please enter the date")
    public void setDateNow(Date now) { this.now = now; }
    public Date getDateNow() { return now; }
 
    @RequiredStringValidator(message = "Please enter a name", trim = true)
    public void setNom(String name) { this.nom = name; }
    public String getNom() { return this.nom; }
    */
 
	public void doPost(
		HttpServletRequest request,
		HttpServletResponse response)
		throws ServletException, IOException {
		try {
			log.info("****************entree dans la méthode doPost*****************");
			// read a String-object from applet
			// instead of a String-object, you can transmit any object, which
			// is known to the servlet and to the applet
			InputStream in = request.getInputStream();
			ObjectInputStream inputFromApplet = new ObjectInputStream(in);
			String echo = (String) inputFromApplet.readObject();
			log.info("****************Message applet" +echo);
 
			// echo it to the applet
			OutputStream outstr = response.getOutputStream();
			ObjectOutputStream oos = new ObjectOutputStream(outstr);
			oos.writeObject(echo);
			oos.flush();
			oos.close();
 
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
 
	public void doGet(
		HttpServletRequest request,
		HttpServletResponse response)
		throws ServletException, IOException {
		try {
			log.info("****************entree dans la méthode doGet*****************");
			// read a String-object from applet
			// instead of a String-object, you can transmit any object, which
			// is known to the servlet and to the applet
			InputStream in = request.getInputStream();
			ObjectInputStream inputFromApplet = new ObjectInputStream(in);
			String echo = (String) inputFromApplet.readObject();
			log.info("****************Message applet" +echo);
 
			// echo it to the applet
			OutputStream outstr = response.getOutputStream();
			ObjectOutputStream oos = new ObjectOutputStream(outstr);
			oos.writeObject(echo);
			oos.flush();
			oos.close();
 
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
 
	public String execute(HttpServletRequest request,HttpServletResponse response) throws Exception {
		log.info("****************entree dans la méthode execute*****************");
		String retour = SUCCESS;
    	try {
    		/*cpsService.isConnecte();
 
			if (userCarteCps != null && userCarteCps.getIdentifiant() != null) {
				retour = SUCCESS;
			} else {
				addActionError(getText("erreur.login.session"));
	    		retour = ERROR_SESSION;
			}*/
    	} catch (Exception e) {
    		addActionError(getText("erreur.login.session"));
    		retour = ERROR_SESSION;
    	}
        return retour;
    }
}
Et voici le message d'erreur:
java.io.streamcorruptedexception invalid stream header 3C21444F

La ligne concernée est ObjectInputStream inputFromServlet = new ObjectInputStream(instr);
probordelais est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 12/10/2011, 11h44   #2
Membre du Club
 
Homme Mathieu
Ingénieur développement logiciels
Inscription : juin 2006
Messages : 154
Détails du profil
Informations personnelles :
Nom : Homme Mathieu
Âge : 28
Localisation : France, Gironde (Aquitaine)

Informations professionnelles :
Activité : Ingénieur développement logiciels
Secteur : High Tech - Éditeur de logiciels

Informations forums :
Inscription : juin 2006
Messages : 154
Points : 50
Points : 50
Pour tester j'ai créé une servlet "classique" avec le même code

Code :
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
public class CommunicationApplet extends HttpServlet {
 
	private static Logger log = Logger.getLogger(CommunicationApplet.class);	
 
	public void doGet(HttpServletRequest req, HttpServletResponse res)
			throws ServletException, IOException {
 
		res.setContentType("text/html");
		PrintWriter out = res.getWriter();
		out.println("<HTML>");
		out.println("<HEAD><TITLE> Titre </TITLE></HEAD>");
		out.println("<BODY>");
		out.println("Ma première servlet");
		out.println("</BODY>");
		out.println("</HTML>");
		out.close();
	}
 
	public void doPost(HttpServletRequest req, HttpServletResponse res)
			throws ServletException, IOException {
 
		try {
			log.info("****************entree dans la méthode doPost*****************");
			// read a String-object from applet
			// instead of a String-object, you can transmit any object, which
			// is known to the servlet and to the applet
			InputStream in = req.getInputStream();
			ObjectInputStream inputFromApplet = new ObjectInputStream(in);
			String echo = (String) inputFromApplet.readObject();
			log.info("****************Message applet" +echo);
 
			// echo it to the applet
			OutputStream outstr = res.getOutputStream();
			ObjectOutputStream oos = new ObjectOutputStream(outstr);
			oos.writeObject(echo);
			oos.flush();
			oos.close();
 
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
Et là ça marche... Pourquoi avec ma classe action struts ça ne marche pas?
probordelais est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 12/10/2011, 12h03   #3
Modérateur
 
Avatar de OButterlin
 
Homme
Inscription : novembre 2006
Messages : 5 063
Détails du profil
Informations personnelles :
Sexe : Homme
Localisation : France

Informations forums :
Inscription : novembre 2006
Messages : 5 063
Points : 5 654
Points : 5 654
Peut-être lié au content-type... à tester...
OButterlin est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 12/10/2011, 14h05   #4
Membre du Club
 
Homme Mathieu
Ingénieur développement logiciels
Inscription : juin 2006
Messages : 154
Détails du profil
Informations personnelles :
Nom : Homme Mathieu
Âge : 28
Localisation : France, Gironde (Aquitaine)

Informations professionnelles :
Activité : Ingénieur développement logiciels
Secteur : High Tech - Éditeur de logiciels

Informations forums :
Inscription : juin 2006
Messages : 154
Points : 50
Points : 50
J'avais essayé mais c'est pareil...

Je pense que c'est dû au fait que ma classe action struts n'extends pas HttpServlet...
probordelais est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 12/10/2011, 14h52   #5
Modérateur
 
Avatar de OButterlin
 
Homme
Inscription : novembre 2006
Messages : 5 063
Détails du profil
Informations personnelles :
Sexe : Homme
Localisation : France

Informations forums :
Inscription : novembre 2006
Messages : 5 063
Points : 5 654
Points : 5 654
Je ne pense pas, tout au bout de la chaîne struts il y a une servlet.
OButterlin est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 04h37.


 
 
 
 
Partenaires

Hébergement Web