Per comprobar que funciona:
Fitxer HTML de prova:
-----------------------------------------------------
Nom:
------------------------------------------------------
el copiem a TOMCAT_HOME/examples/hola.html
Servidor
------------------------------------------------------
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class hola extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
res.setContentType("text/html");
PrintWriter out = res.getWriter();
String nom = req.getParameter("nom");
out.println("Hi, "+ nom + "!.");
}
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
doGet(req, res);
}
}
-------------------------------------------------------
Compilem amb javac hola.java i obtenim hola.class. Copiem el hola.class a TOMCAT_HOME/examples/WEB-INF/classes.
Cridem des d'un navegador a:
http://127.0.0.1:8080/examples/hola.html
omplim el nom i cliquem a POST.
Si obtenim quelcom com:
Hi, nom!
Anem bé!
No hay comentarios:
Publicar un comentario