Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在代码中添加参数时出错_Java_Jsp_Tomcat - Fatal编程技术网

Java 在代码中添加参数时出错

Java 在代码中添加参数时出错,java,jsp,tomcat,Java,Jsp,Tomcat,您可以在JSP中声明类,但不推荐这样做 你也可以这么做,但我不建议你这么做 exception org.apache.jasper.JasperException: Unable to compile class for JSP An error occurred at line: 7 in the jsp file: /projedct/reco.jsp Generated servlet error: Syntax error on token ")", { expected after

您可以在JSP中声明类,但不推荐这样做

你也可以这么做,但我不建议你这么做

exception

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

An error occurred at line: 7 in the jsp file: /projedct/reco.jsp
Generated servlet error:
Syntax error on token ")", { expected after this token

An error occurred at line: 7 in the jsp file: /projedct/reco.jsp
Generated servlet error:
Syntax error on token "}", delete this token

An error occurred at line: 7 in the jsp file: /projedct/reco.jsp
Generated servlet error:
Syntax error on token ")", { expected after this token

An error occurred at line: 7 in the jsp file: /projedct/reco.jsp
Generated servlet error:
Syntax error, insert "}" to complete Block

An error occurred at line: 7 in the jsp file: /projedct/reco.jsp
Generated servlet error:
Syntax error, insert "}" to complete Block

An error occurred at line: 7 in the jsp file: /projedct/reco.jsp
Generated servlet error:
Syntax error, insert "}" to complete Block


    org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:84)
    org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:328)
    org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:409)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:288)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:267)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:255)
    org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:563)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:293)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
note The full stack trace of the root cause is available in the Apache Tomcat/5.5.12 logs.

Apache Tomcat/5.5.12

错误在于:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1" import="java.sql.*,java.util.*,java.lang.*;"%>
<%
String abc=request.getParameter("q");
out.println(abc);
%>
<%   
 int count=0;
        // TODO Auto-generated method stub
try
{
            Class.forName("org.postgresql.Driver");
            } 
catch (ClassNotFoundException cnfe)
{
             // out.println("Could not find the JDBC driver!");
              System.exit(1);
            }

        // out.println("PostgreSQL JDBC Driver Registered!");

        Connection connection = null;

        try {

            connection = DriverManager.getConnection(
                    "jdbc:postgresql://localhost/test", "postgres",
                    "manafara");
            connection.setAutoCommit(false);


            Statement st1=connection.createStatement();

            ResultSet rs1=st1.executeQuery("Select COUNT(*) AS TOTAL from groc1");
            int n=0;
            while(rs1.next())
            {n=rs1.getInt("TOTAL");}
            // out.println("Count: " +n);

        rs1.close();

            Double db[][]=new Double[n][2];
            Statement st=connection.createStatement();
            ResultSet rs=st.executeQuery("Select * from groc1 ");
                for(int a=0; rs.next(); a++)
            { db[a][0]=(double)rs.getInt(4);
            db[a][1]=rs.getDouble(6);

            }

        // out.println("data fetched: ");
        // out.print(" \t cost quantity \n");
        for(int i=0;i<n;i++)
        {
            // out.print(i+"\t");
            for(int j=0;j<2;j++)
            {
                // out.print(db[i][j]+"\t");
            }
            // out.println();
        }
        // out.println();
        Double inf=Double.POSITIVE_INFINITY;
        Double[][] dist=new Double[n][n];//precomputed distance betn i and j
        int[] davg=new int[n];//array of index of closest clusters for each i
        int store[][]=new int[n][n];

        for(int i=0;i<n;i++)
        {
            for(int j=0;j<n;j++)
            {
                if(i==j)
                {
                    dist[i][j]=inf;

                }
                else dist[i][j]= distance(db[i],db[j]);
                if(dist[i][j]<dist[i][davg[i]])
                    davg[i]=j;//store closest pairs index
            }

        }
        // out.println("initial dist matrix");
        for(int i=0;i<n;i++)
        {
            // out.print(i+":\t");
            for(int j=0;j<=i;j++)
            {
                // out.print((dist[i][j])+"");

                if(dist[i][j]!=inf)
                    // out.print("\t");     
            }
            // out.println();
        }
        // out.print("\t");
        for(int i=0;i<n;i++)
        {
            // out.print(i+"\t");
        }
        // out.println();
        int s1;
for( s1=0;s1<n-1;s1++)
{ //update davg[]
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<n;j++)
            {
                if(i==j)
                    dist[i][j]=inf;
                if(dist[i][j]<dist[i][davg[i]])
                    davg[i]=j;

            }
        }
        //find closest pair of clusters(pos, pos1)
        int pos=0;




        for(int b=0;b<n;b++)

{   int p=0;
            while(dist[b][davg[b]]<5)
            {


                if(dist[b][davg[b]]<dist[pos][davg[pos]])
                pos=b;


        int pos1=davg[pos];


            // out.println("pts "+(pos)+" and "+(pos1)+" are clustered hence new point is("+(pos)+" , "+(pos1)+")");

            store[b][p]=pos1;




    for(int i=0;i<n;i++)
        {// out.print(i +":  ");
        for(int j=0; j<n; j++)

            // out.print(store[i][j]+" ");
    // out.println();
        }
            for(int j=0;j<n;j++)
        {

                //if(dist[pos1][j]<dist[pos][j]) **single linkage
                    //  dist[pos][j]=dist[j][pos]=dist[pos1][j];
            //dist[pos][pos]=inf;

                dist[pos][j]=dist[j][pos]=((dist[pos][j]+dist[pos1][j])/2);//average linkage
                dist[pos][pos]=inf;
        }

            for(int i=0;i<n;i++)
        {
            dist[pos1][i]=dist[i][pos1]=inf;

        }

            for(int j=0;j<n;j++)
        {
            if(davg[j]==pos1)
                davg[j]=pos;
            if(dist[pos][j]<dist[pos][davg[pos]])
                davg[pos]=j;
        }



            for(int i=0;i<n;i++)
{
    // out.print(i+":\t");
    for(int j=0;j<=i;j++)
    {
        // out.print((dist[i][j])+"");

        if(dist[i][j]!=inf)
            // out.print("\t");     
    }
    // out.println();
}
// out.print("\t");

    for(int i=0;i<n;i++)
{
    // out.print(i+"\t");
}

    // out.println("\n");


p++;
count++;
            }//while
            }//for p

}//big for  

// out.println("no of clusters iterations"+count);
        }//try

        catch(Exception e)
        {// out.println("exception");}  


%>


 //for methods you need to use <%!  %>

    <%!     public Double distance(Double db1[], Double db2[])
        {
            double temp=(Math.pow((db2[0]-db1[0]),2)) + (Math.pow((db2[1]-db1[1]),2));
            double db= Math.sqrt(temp);
            return (db);

        }

%>
在那里:

            if(dist[i][j]!=inf)
                // out.print("\t");     
        }

在这里发布之前,请在格式化您的代码方面投入更多精力,并在学习您正在使用的语言的规则和语法方面投入一点工作。
            if(dist[i][j]!=inf)
                // out.print("\t");     
        }
    if(dist[i][j]!=inf)
        // out.print("\t");     
        }