witam, chciałem sie dowiedzieć czy mogę wysłać obiekt do servletu za pomocą żądania get, nie wiem dlaczego mi to nie działa proszę o podpowiedz.
metoda wysyłająca obiekt wygląda tak
public void sendObjectToServlet(Object object, String arg) {
String servletGet = webServerStr + "?" + "Action" + "=" + arg;
ObjectOutputStream outputToServlet = null;
try{
URL controlerServlet = new URL( servletGet );
URLConnection servletConnection = controlerServlet.openConnection();
servletConnection.setDoInput(true);
servletConnection.setDoOutput(true);
servletConnection.setUseCaches (false);
servletConnection.setDefaultUseCaches (false);
servletConnection.setRequestProperty("Content-Type", "application/octet-stream");
outputToServlet = new ObjectOutputStream(servletConnection.getOutputStream());
outputToServlet.writeObject(object);
outputToServlet.flush();
outputToServlet.close();
}catch (Exception e)
{
e.printStackTrace();
}
}
natomiast po stronie servletu wygląda to tak :
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String action = null;
action = request.getParameterValues("Action")[0];
AccessDB accessDB = new AccessDB();
if(action.equals("AddKontrahent")) {
Kontrahent kontrahent = null;
kontrahent = getKontrahentFromApplet(request);
try {
accessDB.addKontrahent(kontrahent);
} catch (SQLException ex) {
ex.printStackTrace();
}
}
}
protected Kontrahent getKontrahentFromApplet(HttpServletRequest request) {
Kontrahent kontrahent = null;
ObjectInputStream inputFromApplet = null;
try{
inputFromApplet = new ObjectInputStream(request.getInputStream());
kontrahent = (Kontrahent) inputFromApplet.readObject();
inputFromApplet.close();
}catch (Exception e)
{
e.printStackTrace();
}
return kontrahent;
}