Ho trovato la soluzione al dilemma
Ecco cosa ho dovuto fare per risolvere il problema della mancata ricezione della stringa:
nel metodo post della servlet ho fatto cosi:
codice:
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
try {
InputStream in = request.getInputStream();
if (in!=null)
{
ObjectInputStream inputFromApplet = new ObjectInputStream(in);
String echo = (String) inputFromApplet.readObject();
System.out.println("valore arrivato :"+echo);
// questo codice per rinviare all'applet la stringa inviata alla servlet
response.setContentType("application/x-java-serialized-object");
OutputStream outstr = response.getOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(outstr);
oos.writeObject(echo);
oos.flush();
oos.close();
}
............
ovviamente l'applet è stata modificata in modo tale da ricevere la stringa:
codice:
try {
URL urlServlet = new URL("http://localhost:8080/web/TrovaCapitoliServlet");
//URL urlServlet = new URL(getCodeBase(),"TrovaCapitoliServlet");
System.out.println(urlServlet.toString());
HttpURLConnection con = (HttpURLConnection)urlServlet.openConnection();
con.setRequestMethod("POST");
con.setDoInput(true);
con.setDoOutput(true);
con.setUseCaches(false);
con.setRequestProperty("Content-Type","application/x-java-serialized-object");
String invio=new String("PIPPO");
ObjectOutputStream oos = new ObjectOutputStream(con.getOutputStream());
oos.writeObject(invio);
oos.flush();
oos.close();
// Getting request reponse code
int code = con.getResponseCode();
// Response is OK
String v[]=new String[1];
if (code == 200)
{
// Retrieving servlet response
ObjectInputStream inputStream = new ObjectInputStream(con.getInputStream());
try {
v[0]= new String((String) inputStream.readObject());
} catch (ClassNotFoundException e1) {
e1.printStackTrace();
}
inputStream.close();
}
else
{
v[0]= new String("Servlet request has failed! Response code is: " + code);
System.out.println("Servlet request has failed! Response code is: " + code);
}
tableList.setListData(v);
} catch (MalformedURLException e1) {
e1.printStackTrace();
} catch (ProtocolException e1) {
OK ....