rafaelglauber 1 de nov. de 2007
não entendi bem a pergunta, você quer executar uma classe que tenha o método “main”? é isso?
jason_bourne 1 de nov. de 2007
é…não precisa ser o main…pode ser qualquer outra.
rafaelglauber 1 de nov. de 2007
Retirado de: Wesley, Addison. JavaServer Pages, Second Edition
9.16 Using Java in JSPs
As mentioned, a JSP turns into a servlet, and a servlet is simply a Java class. This implies that page authors should be able to embed Java directly in JSPs and that this Java code will then be automatically carried over into the resulting servlet by the page translator. This is indeed the case, and the tag that does this is jsp:scriptlet. Any java code between jsp:scriptlet and the closing </jsp:scriptlet> will be put, unchanged, into the servlet. As a convenience, the same effect can be achieved by enclosing code within <% … %> tags.
It is possible to use these tags to write information directly to the page, as in
<% out.println("The time is now: " +
new java.util.Date()); %>
This is a complete Java statement, including the closing semicolon. The variable out, within a JSP page, refers to a special output mechanism that writes the enclosed data to the user or to any custom tag that may be collecting data. This object is the origin of the name c:out in the standard tag library.
Scriptlets can also introduce control structures:
<% for(int i=0;i<10;i++) { %>
Hello!
<% } %>
This will send Hello!
to the output page ten times. When the servlet is built, the first line with the for will be injected, complete with the opening brace. Then the hello line will be added and then the second scriptlet with the closing brace. The result will be a complete valid Java block.
A great deal of care must be applied when using scriptlets in this fashion; it is all too easy to miss a closing brace or accidently fail to close the scriptlet in the right place, leading to difficult-to-find problems. In almost every circumstance, it is preferable to use the corresponding control tags from the standard libraries.
It is also possible to get and use beans and access session data from within scriptlets. In fact, it is possible to do anything in a scriplet that can be done from a servlet, precisely because scriplet code goes directly into the servlet constructed by the page translator.
pesquise sobre SCRIPTLET no google.
Pedrosa 1 de nov. de 2007
Não incentive o uso de drogas!
furutani 1 de nov. de 2007
Olá
eduacsp:
Pessoal,
Qual é o melhor método de chamar uma classe (no caso o main) através do jsp?
O melhor mesmo é não usar. Mas você usar a tag jsp:useBean para instanciar uma classe e usar jsp:getProperty para chamar um método e obter o valor de dele.
rafaelglauber 1 de nov. de 2007
só postei uma possibilidade :lol:
jason_bourne 4 de nov. de 2007
+/- isso?
<jsp:useBean id=“principal” scope=“page” class=“main.Principal” />
<%
principal . inicio ();
%>
jason_bourne 4 de nov. de 2007
+/- isso?
<jsp:useBean id="principal" scope="page" class="main.Principal" />
<%
principal . inicio ();
%>