I'm trying to send post data from my japplet to my servlet "Connexion" but the output that i placed in my servlet init method and processRequest method are never displayed in my console.
Here is the send method call in my japplet
private void jButtonEntrerActionPerformed(java.awt.event.ActionEvent evt) {
try {
String infos = "login=" + URLEncoder.encode(FieldLogin.getText(), "UTF-8")
+ "&mdp=" + URLEncoder.encode(FieldMdp.getText(), "UTF-8")+"&action=Login";
//"http://localhost:8088/Web_Applic_Achats_2/Connexion"
SendPost("/Connexion", infos, getCodeBase());
} catch (UnsupportedEncodingException ex) {
Logger.getLogger(Register.class.getName()).log(Level.SEVERE, null, ex);
}
}
The sendPost method definition (in abstract class Send)
public static void SendPost(String dest, String infos, URL pageCourante)
{
try {
URL url = new URL (pageCourante, dest);
URLConnection connection = url.openConnection();
connection.setDoOutput(true);
connection.setUseCaches(false);
connection.setDefaultUseCaches(false);
try (OutputStreamWriter out = new OutputStreamWriter( connection.getOutputStream())) {
out.write(infos);
}
} catch (MalformedURLException ex) {
System.out.println("Err url: "+ex.getLocalizedMessage());
} catch (IOException ex) {
System.out.println("IO envoi: "+ex.getLocalizedMessage());
}
}
And finally my servlet Connexion
public class Connexion extends HttpServlet{
BeanBDAccess bdAccess= null;
ServletContext sc;
@Override
public void init() throws ServletException {
System.out.println("Hey init");
try {
bdAccess= new BeanBDAccessMysql("BD_SOCIETE", "root", "boulaite");
} catch (Exception ex) {
Logger.getLogger(Connexion.class.getName()).log(Level.SEVERE, null, ex);
}
sc = getServletContext();
}
@Override
public void destroy() {
if(bdAccess != null)
{
try {
bdAccess.FermerConnectionBd();
} catch (Exception ex) {
Logger.getLogger(Connexion.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
System.out.println("Hey processRequest");
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=UTF-8");
// .... code ....
}
}
EDIT
I ran many test and noticed that i don't have my parameter or my complete request uri in the http server monitor (netbeans). But when i output the url in my applet the url is ok.
Last edit:
I don't know if it will change something but I noticed in the http server monitor that I'm getting a 304 statut: exit not modified