Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2014
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.73 KB | None | 0 0
  1. <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
  2. pageEncoding="ISO-8859-1"%>
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  4. <html>
  5. <head>
  6. <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
  7. <title>Data (sem JavaBeans)</title>
  8. </head>
  9. <body>
  10.  
  11. <a href="Data">Atualizar data</a>
  12. <br/>
  13.  
  14. <%
  15.  
  16. if (request.getAttribute("dia") != null)
  17. {
  18. int dia = (Integer) request.getAttribute("dia");
  19. int mes = (Integer) request.getAttribute("mes");
  20. int ano = (Integer) request.getAttribute("ano");
  21. int hora = (Integer) request.getAttribute("hora");
  22. int minuto = (Integer) request.getAttribute("minuto");
  23.  
  24. String sDia = String.format("%2d",Integer.toString(dia));
  25. String sMes = String.format("%2d",Integer.toString(mes));
  26. String sAno = String.format("%4d",Integer.toString(ano));
  27. String sHora = String.format("%2d",Integer.toString(hora));
  28. String sMinuto = String.format("%2d",Integer.toString(minuto));
  29.  
  30. out.print("A hora atual é: " + sDia + "/" + sMes + "/" + sAno + " - " + sHora + ":" + sMinuto);
  31. }
  32. %>
  33. </body>
  34. </html>
  35.  
  36. package br.com.gabriel;
  37.  
  38. import java.io.IOException;
  39. import java.util.Calendar;
  40. import java.util.Date;
  41.  
  42. import javax.servlet.ServletException;
  43. import javax.servlet.annotation.WebServlet;
  44. import javax.servlet.http.HttpServlet;
  45. import javax.servlet.http.HttpServletRequest;
  46. import javax.servlet.http.HttpServletResponse;
  47.  
  48. /**
  49. * Servlet implementation class Data
  50. */
  51. @WebServlet("/Data")
  52. public class Data extends HttpServlet {
  53. private static final long serialVersionUID = 1L;
  54.  
  55. /**
  56. * @see HttpServlet#HttpServlet()
  57. */
  58. public Data() {
  59. super();
  60. // TODO Auto-generated constructor stub
  61. }
  62.  
  63. /**
  64. * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
  65. */
  66. @SuppressWarnings("deprecation")
  67. protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  68.  
  69. Date d = new Date();
  70.  
  71. int dia = d.getDate();
  72. int mes = d.getMonth() + 1;
  73. int ano = d.getYear() + 1900;
  74. int hora = d.getHours();
  75. int minuto = d.getMinutes();
  76.  
  77. request.setAttribute("dia", dia);
  78. request.setAttribute("mes", mes);
  79. request.setAttribute("ano", ano);
  80. request.setAttribute("hora", hora);
  81. request.setAttribute("minuto", minuto);
  82.  
  83. request.getRequestDispatcher("index.jsp").forward(request, response);
  84. };
  85. }
  86.  
  87. java.util.IllegalFormatConversionException: d != java.lang.String
  88.  
  89. String sDia = String.format("%2d",Integer.toString(dia));
  90.  
  91. %2d
  92.  
  93. String sDia = String.format("%2d", dia);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement