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
| import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.URLDecoder;
import java.io.UnsupportedEncodingException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class Application extends HttpServlet {
private static final long serialVersionUID = 644942366480920087L;
private static String[] tab = null;
private static String url = "url";
private static boolean identBon = true;
public Application(){
}
public void destroy(){
super.destroy();
}
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException{
PrintWriter out = res.getWriter();
while(url != null){
for(int i = 0; i <= tab.length; i++){
try{
url = URLDecoder.decode(tab[i].toString(), "UTF-8");
}
catch(UnsupportedEncodingException e){
out.println(e);
}
}
if(url.substring(0).equals("UniqueID")){
if("1015".equals("login") || "1015".equals("password") || "0000".equals("password")){
out.println("C'est un Login et password valides" + identBon);
out.println("login :"+ req.getParameter("login"));
out.println("pass word :"+ req.getParameter("password"));
out.println("UniqueID :"+ req.getParameter("UniqueID"));
try{
InputStream is = new FileInputStream("http://localhost:8080/converso-server/"); //505-1.wwq converso t'envoie le fichier demandé par mobile
OutputStream os = res.getOutputStream();
res.setContentType("text/plain");
res.setHeader("Content-Disposition", "attachment;filename = testNumeric.wwq");
int count;
byte buf[] = new byte[4096];
while((count = is.read(buf)) > -1){
os.write(buf, 0, count);
is.close();
os.close();
}
}
catch(IOException ex){
ex.getMessage();
out.println("Le chargement du fichier a échoué!!!");
}
out.println("Le fichier était bien chargé, Ok!!");
out.flush();
out.close();
}
else{
out.println("Mauvaise identification."+ !identBon +"Réessayer encore");
}
}
else{
out.println("Rien ne correspond à UniqueID");
}
}
}
public void init() throws ServletException{
super.init();
}
} |
Partager