aspose file tools*
The moose likes Beginning Java and the fly likes Problem in GET and POST Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Problem in GET and POST" Watch "Problem in GET and POST" New topic
Author

Problem in GET and POST

Adriana Cardoso
Greenhorn

Joined: Oct 05, 2005
Posts: 6
Hi,
I need some help can there is class ArtigoServlet02.java with two metodos get and post..Because I am trying to compile this codigo and this giving mistake in metodos .
Can have two get and post ? It follows below :
package servlets.artigos;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import java.util.*;

/**
*
* @see
*/
public class ArtigoServlet02 extends HttpServlet {
/**
*
* @param solicitacao
* @param resposta
* @throws java.io.IOException
* @throws javax.servlet.ServletException
*/
public void doPost(HttpServletRequest solicitacao , HttpServletResponse resposta)throws IOException ,ServletException {

Connection conexao;
PreparedStatement declaracao;
ResultSet resultado=null;
String pesquisa;
String resulNome= null;
String ultAcesAdm= null;
String idAdm= "";
String acessoAtual;
Random aleatorio;
try {
Class.forName("org.firebirdsql.jdbc.FBDriver").newInstance();
} catch (Exception e) {

}
String nomeAdm = solicitacao.getParameter("nome").trim();
String senhaAdm= solicitacao.getParameter("senha").trim();
if (nomeAdm.length()== 0 || senhaAdm.length()== 0){
resposta.setContentType("text/html");
PrintWriter out = resposta.getWriter();
out.println("<html>");
out.println("<head>");
out.println("<title>Opcoes</title>");
out.println("<meta http-equiv='refresch' content='4' url=javascript:history.back();>");
out.println("</head>");
out.println("<body bgcolor='#FFFFF'>");
out.println("<h1>Preencha todos os campos!>");
out.println("<body>");
out.println("</htlm>");
} else{
try{
conexao = DriverManager.getConnection("jdbc:firebirdsql://localhost:3050/examples/EMPLOYEE.fdb");
pesquisa="SELECT * FROM administratores WHERE nome = ? AND senha= ?";
declaracao = conexao.prepareStatement(pesquisa);
declaracao.setString(1, nomeAdm);
declaracao.setString(2, senhaAdm);
resultado=declaracao.executeQuery();
resultado.next();
resultNome= resultado.getString("nome");
ultAcesAdm= resultado.getString("ultimo _acesso");
} catch (SQLException e) {
System.err.println(e);
{
}
if (resulNome ==null) {
resposta.setContentType("text/html");
PrintWriter out = resposta.getWriter();
out.println("<html>");
out.println("<head>");
out.println("<title>Opcoes</title>");
out.println("<meta http-equiv='refresch' content='4' url=javascript:history.back();>");
out.println("</head>");
out.println("<body bgcolor='#FFFFFF'>");
out.println("<h1>Usuario nao cadastrado verifique os dados.</h1>");
out.println("<body>");
out.println("</htlm>");
} else {
aleatorio= new Random();
for (int i= 0 ; i < 15 ; i++) {
idAdm+=aleatorio.nexInt(100);
}
CIData dtAtual = new CIData();
dtAtual.setDataAtual();
acessoAtual = dtAtual.getDataAtual();
try {
conexao = DriverManager.getConnection("jdbc:firebirdsql://localhost:3050/examples/EMPLOYEE.fdb");
pesquisa = "UPDATE administratores SET id_sessao= ? , ultimo_acesso= ? WHERE nome=? AND senha = ? AND ultimo_acesso=?";
declaracao = conexao.prepareStatement(pesquisa);
declaracao.setString(1 ,idAdm);
declaracao.setString(2, acessoAtual);
declaracao.setString(3, resulNome);
declaracao.setString(4, senhaAdm);
declaracao.setString(5, ultAcesAdm);
declaracao.executeUpdate();
} catch
(SQLException e) {
System.err.println(e);
}
Cookie cookieSes = new Cookie("administrator", idAdm);
HttpSession sessaoAdm = solicitacao.getSession(true);
IdSessao atIdSessao = new IdSessao();
atIdSessao.setIdSessao(idAdm);
sessao.Adm.setAttribute("atIdSessaoAdm" ,atIdSessao);
resposta.setContentType("text/html");
PrinterWriter out = resposta.getWriter();
resposta.addCookie(cookieSes);
out.println("<html>");
out.println("<head>");
out.println("<title>Opcoes</title>");
out.println("<body bgcolor='#FFFFFF'>");
out.println("<table border='0' widht ='350' bgcolor='#cccccc'>");
out.println("tr><td bgcolor='#ccc00'>");
out.println("Seja Bem Vindo"+ resulNome + "+.<br>");
out.println("</td></tr>");
out.println("<tr>");
out.println("<td align='center'>");
out.println("<font face= 'Verdana'>Selecione uma das opcoes</font></td>");
out.println("</tr>");
out.println("</table>");
out.println("<p><a href='as03'>Exclusao de novo artigo</a></p>");
out.println("<p><a href='as04'>Atualizacao de artigos</a></p>");
out.println("</body>");
out.println("</html>");
}
}
}

public void doGet(HttpServletRequest solicitacao , HttpServletResponse resposta)throws IOException ,ServletException //MISTAKE
{

Connection conexao;
PreparedStatement declaracao;
ResultSet resultado=null;
String pesquisa;
String resulNome = null;
String ultAcesAdm=null;
String idAdm="";
IdSessao recupAtIdSessao;
String idSessaoAdm= "0";
HttpSession sessaoAdm;
try {
ssesaoAdm=solicitacao.getSession(true);
recupAtIdSessao= (IdSessao)sessaoAdm.getAttribute("atIdSessaoAdm");
idSessaoAdm=recupAtIdSessao.getIdSessao();
} catch (Exception e) {
}
try {

conexao = DriverManager.getConnection("jdbc:firebirdsql://localhost:3050/examples/EMPLOYEE.fdb");
pesquisa="SELECT * FROM administratores WHERE id_sessao= ? ";
declaracao = conexao.prepareStatement(pesquisa);
declaracao.setString(1, idSessaoAdm);
resultado=declaracao.executeQuery();
while( result.next()) {
resulNome=resultado.getString("nome");
ultAcesAdm=rsultado.getString("ultmo_acesso");
} catch (SQLException e) {
System.err.print(e);
}
if (resulNome==null);
{
resposta.setContentType("text/html");
PrintWriter out = resposta.getWriter();
out.println("<html>");
out.println("<head>");
out.println("<title>Opcoes</title>");
out.println("<meta http-equiv='refresch' content='4 url=as01'>");
out.println("</head>");
out.println("<body bgcolor='#FFFFFF'>");
out.println("<center><h1>Sua presen�a nesta sessao nao est� autorizada<br>IDENTIFIQUE-SE</h1></center>");
out.println("<body>");
out.println("</htlm>");

} else {
resposta.setContentType("text/html");
PrintWriter out = resposta.getWriter();
out.println("<html>");
out.println("<head>");
out.println("<title>Opcoes</title>");
out.println("</head>");
out.println("<body bgcolor='#FFFFFF'>");
out.println("<table border='0' widht ='350' bgcolor='#cccccc'>");
out.println("tr><td bgcolor='#ccc00'>");
out.println("Seja Bem Vindo"+ resulNome + "+.<br>");
out.println("Seu ultimo acesso foi em "+ultAcesAm+<"<br>");
out.println("<td></tr>");
out.println("<tr>");
out.println("<td align='center'>");
out.println("<font face= 'Verdana'>Selecione uma das opcoes</font></td>");
out.println("</tr>");
out.println("</table>");
out.println("<p><a href='as03'>Exclusao de novo artigo</a></p>");
out.println("<p><a href='as04'>Atualizacao de artigos</a></p>");
out.println("<p><a href='as05'>Exclusao de artigos</a></p>");
out.println("</body>");
out.println("</html>");

}

}


}

I wait your help

Adriana
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61623
    
  67

I am trying to compile this codigo and this giving mistake in metodos


It might be helpful for you to post the error that you are getting.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Adriana Cardoso
Greenhorn

Joined: Oct 05, 2005
Posts: 6
Hi ,

The mistake in Netbeans :
init:
deps-jar:
Compiling 1 source file to C:\Documents and Settings\Adriana\Java Deitel\build\classes
C:\Documents and Settings\Adriana\Java Deitel\src\servlets\artigos\ArtigoServlet02.java:129: illegal start of expression
public void doGet(HttpServletRequest solicitacao , HttpServletResponse resposta)throws IOException ,ServletException {
C:\Documents and Settings\Adriana\Java Deitel\src\servlets\artigos\ArtigoServlet02.java:205: ';' expected

2 errors
BUILD FAILED (total time: 2 seconds)

Thanks
Adriana
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
In your doPost, right after System.err.println(e); you have {, I believe you need a } there.


Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
Adriana Cardoso
Greenhorn

Joined: Oct 05, 2005
Posts: 6
HI,

Still is with this illegal mistake sarted with expression in metodo doGet I tried many times.

Thanks,

Adriana
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61623
    
  67

This has nothing to do with JSP. You merely need to get your syntax straightened out. Moved to Java in General (beginner).
Adriana Cardoso
Greenhorn

Joined: Oct 05, 2005
Posts: 6
Hi,
I found the mistake

Thanks to everybody

---------------------------------
Adriana - Brazil
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Problem in GET and POST