Olá a todos.
Em meu projeto web eu estou conseguindo cadastrar normalmente.
Mas quando fui criar uma nova página de cadastro, apenas copiei e colei o conteúdo e fiz as alterações necessárias.
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: 6 in the generated java file
Syntax error on token ";", delete this token
Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:423)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:316)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:294)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:281)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:566)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:337)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:390)
<%@page import="java.sql.*;" %>
<%@page import="java.text.DecimalFormat" session="true" %>
<%@page import="java.text.NumberFormat" session="true" %>
<%
int sCod;
try {
sCod = Integer.parseInt(request.getParameter("codigo"));
} catch(NumberFormatException nfex) {
out.println("Código inválido!" + nfex.toString());
return;
}
String sNome = request.getParameter("nome");
String sMarca = request.getParameter("marca");
//DecimalFormat formatPreco = new DecimalFormat("##,##00,00");
float sPreco;
try {
sPreco = Float.parseFloat(request.getParameter("preco"));
} catch(NumberFormatException nfex) {
out.println("Preço inválido!" + nfex.toString());
return;
}
int sQuantid;
try {
sQuantid = Integer.parseInt(request.getParameter("quantid"));
} catch(NumberFormatException nfex) {
out.println("Código inválido!" + nfex.toString());
return;
}
float sDesconto;
try {
sDesconto = Float.parseFloat(request.getParameter("desconto"));
} catch (NumberFormatException nfex) {
out.println("Desconto inválido!" + nfex.toString());
return;
}
%>
<%
Connection con = null;
Statement stmt = null;
try {
Class.forName("org.gjt.mm.mysql.Driver");
String url="jdbc:mysql://localhost:3306/rest_web";
String user="root";
String pass="2017";
con = DriverManager.getConnection(url, user, pass);
stmt = con.createStatement();
String sql = "INSERT produtos SET cod="+sCod+", "+
"nome='"+sNome+"', marca='"+sMarca+"', preco="+sPreco+", "+
"estoque="+sQuantid+", desconto="+sDesconto+";";
stmt.executeUpdate(sql);
%>
<script language="javascript">
alert("Produto cadastrado com sucesso!")
top.document.location.href='cadastro_produtos.jsp';
</script>
<input type=text id=codigo autocomplete="off">
<input type=text id=nome autocomplete="off">
<input type=text id=marca autocomplete="off">
<input type=text id=preco autocomplete="off">
<input type=text id=quantid autocomplete="off">
<input type=text id=desconto autocomplete="off">
<%
} catch (ClassNotFoundException cnfex) {
out.println("Driver não encontrado<br>Erro: " +cnfex.toString());
} catch (SQLException sqlex) {
out.println("Erro ao cadastrar produto:<br>" +sqlex.toString());
}
%>
Não entendi o porque do erro. Está da mesma maneita que aoutra página minha que cadastra normalmente.
Espero uma ajudinha de quem estiver com tempo.
Obrigado.
