4

iam running this code but it is not working .i am using Glassfish with eclipse unable to compile jsp with GlassFish Server Open Source Edition 3.1.2.2,it is showing the following exception here the code

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page language="java" import="java.sql.*" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">

<html>



<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>GlassFish JSP Page</title>

  </head>
  <body>

  <%
   try {     
            Class.forName("com.mysql.jdbc.Driver").newInstance();            
        Connection C =DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root",""); 
            }       catch (Exception E) { 
      System.err.println("Unable to load driver."); 
      E.printStackTrace(); 
            } 

           try{
            Statement stmt=null;
            int val=stmt.executeUpdate("insert into reg(Name,Fname)       values('"+haroon+"','"+hussain+"')");
        if(val==1){
            System.out.println("Data has been inserted :)");
        }else {

            System.out.println("data has not been inserted. :( ");
        }

    } catch (Exception e) {
        e.printStackTrace();
        System.out.println("Cant inserted");
    }

  %>

  </body>
</html> 

ecxeption shown by glassfish

HTTP Status 500 - 

--------------------------------------------------------------------------------

type Exception report

message

descriptionThe server encountered an internal error () that prevented it from     fulfilling this request.

exception 
org.apache.jasper.JasperException: PWC6033: Error in Javac compilation for JSP

 PWC6197: An error occurred at line: 15 in the jsp file: /index.jsp
PWC6199: Generated servlet error:
string:///index_jsp.java:72: cannot find symbol
symbol  : variable haroon
location: class org.apache.jsp.index_jsp

PWC6197: An error occurred at line: 15 in the jsp file: /index.jsp
PWC6199: Generated servlet error:
string:///index_jsp.java:72: cannot find symbol
symbol  : variable hussain
location: class org.apache.jsp.index_jsp



 note The full stack traces of the exception and its root causes are available in the GlassFish Server Open Source Edition 3.1.2.2 logs.

plz any one solve this

user1686810
  • 61
  • 1
  • 1
  • 2
  • The names "haroon" and "hussain" are not Java symbols, and you are no programmer. This is a very unfortunate way to get started here. You invested no time in formatting your question, expect people to spend no time answering it. – reechard Sep 21 '12 at 05:10

2 Answers2

2

You are using variable haroon and hussain and you've never declared them in the JSP. The compiler cannot find the variable anywhere in the generated servlet code.


I strongly discourage writing scriplets (unless you're doing this for learning purposes) for these well known various reasons.

On that note, if you are passing a variable onto you JSP page, and you want to save it to your DB, something like this suffice:

<%
    String haroon = request.getParameter("haroon");
    String hussain = request.getParameter("hussain");
%>

(Add the tag before doing the DB connection). You can now pass the value by append 2 parameters (haroon and hussain) on your URL (which calls the JSP).

Community
  • 1
  • 1
Buhake Sindi
  • 87,898
  • 29
  • 167
  • 228
1

In my case I was attempting to initialize a TreeSet in a jsp.

TreeSet<String> treeCategories = new TreeSet<>();

This will get: org.apache.jasper.JasperException: PWC6033: Error in Javac compilation for JSP||PWC6199: Generated servlet error... because of the "diamond" or "<>".

I do not recall the exact java terms or usage but <> is some sort of a template or generic or something like that when java really needs, at least in my case, to know what it is:

TreeSet<String> treeCategories = new TreeSet<String>();

That will work.