daily pastebin goal
30%
SHARE
TWEET

Untitled

a guest Jun 17th, 2017 51 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.                                                                      
  2.                                                                      
  3.                                                                      
  4.                                              
  5. import java.io.IOException;
  6. import java.io.PrintWriter;
  7. import javax.servlet.ServletException;
  8. import javax.servlet.http.HttpServlet;
  9. import javax.servlet.http.HttpServletRequest;
  10. import javax.servlet.http.HttpServletResponse;
  11. import com.mysql.jdbc.*;
  12. import java.sql.DriverManager;
  13. import java.sql.ResultSet;
  14. /**
  15.  *
  16.  * @author mafiu
  17.  */
  18. public class feeds extends HttpServlet {
  19.    private java.sql.Connection con;
  20.     protected void processRequest(HttpServletRequest request, HttpServletResponse response)
  21.     throws ServletException, IOException {
  22.         response.setContentType("text/xml;charset=UTF-8");
  23.         PrintWriter out = response.getWriter();
  24.         try {
  25.             String formato = request.getParameter("formato").toString();
  26.  
  27.             Class.forName("com.mysql.jdbc.Driver");
  28.             con = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/multimedios", "multimedios", "multimedios");
  29.             Statement stmt = (Statement) con.createStatement();
  30.             ResultSet result = stmt.executeQuery("select NOTICIA_TITULO, NOTICIA_CONTENIDO, NOTICIA_FECHA from NOTICIA_SERVER;");
  31.  
  32.             if(formato.equals("xml")){
  33.                 out.println("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");
  34.                 out.println("<noticias>");
  35.                 while(result.next()){
  36.                         out.println("<noticia fecha=\""+result.getString("NOTICIA_FECHA")+"\">");
  37.                         out.println("<titulo>"+result.getString("NOTICIA_TITULO")+"</titulo>");
  38.                         out.println("<contenido>"+result.getString("NOTICIA_CONTENIDO")+"</contenido>");
  39.                         out.println("</noticia>");
  40.                 }
  41.                 out.println("</noticias>");
  42.             }
  43.             if(formato.equals("rss")){
  44.                
  45.             }
  46.  
  47.             stmt.close();
  48.  
  49.         } catch (Exception e) {
  50.             e.printStackTrace();
  51.         } finally {
  52.             out.close();
  53.         }
  54.     }
  55.  
  56.     protected void doGet(HttpServletRequest request, HttpServletResponse response)
  57.     throws ServletException, IOException {
  58.         processRequest(request, response);
  59.     }
  60.    
  61.     protected void doPost(HttpServletRequest request, HttpServletResponse response)
  62.     throws ServletException, IOException {
  63.         processRequest(request, response);
  64.     }
  65.  
  66.     public String getServletInfo() {
  67.         return "Short description";
  68.     }// </editor-fold>
  69.  
  70. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top