无法为JSP编译类

时间:2011-05-07 09:42:46

标签: java jsp

我正在使用netbeans在JSP中开展一个项目。

我得到以下错误......但我没有找到java任何文件..请给我一些东西。错误是:

org.apache.jasper.JasperException: Unable to compile class for JSP: 

An error occurred at line: 205 in the generated java file
Syntax error, insert "Finally" to complete TryStatement

An error occurred at line: 206 in the generated java file
Syntax error, insert "}" to complete ClassBody

堆栈跟踪:

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:439)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:349)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:327)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:314)
    org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:589)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)

我使用的文件是:

addNewUser.jsp:

<%@ page language="java" %>
<%@ page session="true" %>
<%@ page import="java.util.*" %>
<HTML>
<head>
    <LINK href="styles.css" type="text/css" rel="stylesheet">
</head>
<SCRIPT LANGUAGE="JavaScript">
<!--
history.go(+1);
function validate(){
 x = document.NewUser.uid;
 y = document.NewUser.pwd;
 z = document.NewUser.auth;
 var ed=x.value;
 var pd=y.value;
 var ad=z.value;
 var pattern = /^([a-zA-Z0-9\_\.]{4,10})$/;
 var Apattern = /^([0-3]{1})$/;
 if(!(pattern.test(ed))){
    alert("Invalid username");
    return false;
    }
 else if(!(pattern.test(pd))){
    alert("Invalid password");
    return false;
    }
 else if(!(Apattern.test(ad))){
    alert("Invalid Authentication");
    return false;
  }
 else
   return true;

}
//-->
</SCRIPT>
<br><br>
<body Class=Grad>

<center>

<BR><BR><br><br>
<FONT FACE="Century Gothic">



<FONT size="2" color="blue" FACE="Century Gothic">

<FORM NAME="NewUser" ACTION="AddNewUser1.jsp" METHOD="POST" onsubmit="return validate()">

<TABLE Border=0 align=center>
<TR class=row_title ALIGN="center">
       <TH COLSPAN="2"> Add user</TH>
</TR>

<TR class=row_even>
    <TD>UserID * </TD>
    <TD><input TYPE=text name=uid size="10" maxlength="10"></TD>
</TR>
<TR class=row_odd>
    <TD>Password * </TD>
    <TD><input TYPE=password name=pwd size="10"  maxlength="20"></TD>
</TR>
<TD><input type=hidden name=auth value=2>
<TR class=row_even>
    <TD><INPUT TYPE=submit name=submit value="Submit">
</TD>
    <TD><INPUT TYPE=reset name=resett value="Reset" > 
</TD>
</TR>
</TABLE>
<A align="center" href="Login.jsp">BACK TO HOME</A>
</FORM>
</BODY>
</HTML>

addNewUser1.jsp:

<%@ page language="java" %>
<%@ page session="true" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.io.*" %>
<%@ page import="java.util.Random" %>

<html>
<head>
<LINK href="styles.css" type="text/css" rel="stylesheet">
<SCRIPT LANGUAGE="JavaScript">
<!--
history.go(+1);

//-->
</SCRIPT>
</head>

<jsp:include page="MultiLevelmenu.htm"/><br><br><body  Class=SC>
<center>

<BR><BR>
<FONT FACE="Century Gothic">

<!--Declaration of varaibles-->

<%! String errormsg ;%>
<%! String disluserid ;%>
<%! String dislpwd ;%>
<%! int auth ;%>


<% 
   /*Retreiving user id and password*/

    disluserid = request.getParameter("uid");
    if(disluserid == null)
    disluserid = "";
    dislpwd = request.getParameter("pwd");
    if(dislpwd == null)
    dislpwd = "";
    String sauth = request.getParameter("auth");
    if(sauth == null)
         auth=0;

        auth = Integer.parseInt(sauth);
    //System.out.println(disluserid+dislnewpwd+dislpwd);

%>

<%

/*Declaration of variables*/

Connection con=null;
Statement stmt=null;
ResultSet rs=null;

String Userid,Password;

try
{

    /*Getting the connection variable from session*/

    con=(Connection)session.getAttribute("connection");
    stmt =  con.createStatement();

    String Query = "SELECT * from student where studentid = \'"+disluserid+"\'";
    System.out.println(Query);
    rs = stmt.executeQuery(Query);

}
catch(Exception e)
{
    System.out.println("Exception"+e);

/* If user provides valid username & password then update the new password to database*/
if(rs.next())
{%>
    <script>
        for(i=1;i<=6;i++) document.write("<br>");
    </script>
        <H3 align="center"> User already exists</H3>
    <BR>
    <center>
        <A href="AddNewUser.jsp"> Back </A>
    </center>
<%  
}
else{
String UpdateQuery = 
"Insert into student values(\'"+disluserid+"\',\'"+dislpwd+"\',"+auth+")";
//System.out.println(UpdateQuery);
    int rowsAffected=stmt.executeUpdate(UpdateQuery);       
    //System.out.println("Rows Affected = " + rowsAffected);
if(rowsAffected==1)
    {%>

    <script>
        for(i=1;i<=10;i++) document.write("<br>");
    </script>
        <H3 align="center">User Created Successfully </H3>
                <A href="AddNewUser.jsp"> Create Another User </A>
                <br/>
                <A href="mynewmenu.jsp"> Home </A>
    <BR>
    <%}
/* If user provides invalid password or username*/
else{%>
    <script>
        for(i=1;i<=6;i++) document.write("<br>");
    </script>
        <H3 align="center">Unable to create user please try again </H3>
    <BR>
<%  }  %>
<%
}

%>
</FONT>
</center>
</BODY>
</html>

1 个答案:

答案 0 :(得分:1)

try {

/*Getting the connection variable from session*/

con=(Connection)session.getAttribute("connection");
stmt =  con.createStatement();

String Query = "SELECT * from student where studentid = \'"+disluserid+"\'";
System.out.println(Query);
rs = stmt.executeQuery(Query);
} catch(Exception e) { System.out.println("Exception"+e);

在上面的代码部分中,您没有完成try的catch块。