2 Replies - 7953 Views - Last Post: 26 November 2012 - 03:07 AM

#1 diamond00811  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 11-December 11

using ngram class in servlet code

Posted 24 July 2012 - 02:46 AM

I am using ngram to divide text into each two words in an array
the problem is the notice shown in code that tells cannot find symbol ngram the code is
package web;
import java.lang.Object;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Scanner;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.sql.DataSource;

public class Freq1 extends HttpServlet {
    private DataSource dataSource;
    private Connection connection;
    private Statement stat;
    int result;
    int count,id;


    @Override
    public void init() throws ServletException {
        try {
            // Get DataSource

            Context initContext  = new InitialContext();
            Context envContext  = (Context)initContext.lookup("java:/comp/env");
            dataSource = (DataSource) envContext.lookup("jdbc/TestDB");

            } catch (NamingException e) {
        }
    }


    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        String  s=null ;
        StringBuffer buffer=new StringBuffer();
        try {
            connection = dataSource.getConnection();
            stat = connection.createStatement();

            } catch (SQLException ex) {
            Logger.getLogger(Freq1.class.getName()).log(Level.SEVERE, null, ex);
        }


        try {
            String [] a = null;
            count=0;
            String word=    new String(request.getParameter("t").getBytes("iso-8859-1"), "UTF-8");

            ResultSet   rs = stat.executeQuery("SELECT * FROM file_control ");

            while(rs.next()){
                id=rs.getInt(1);
                s= rs.getString(8);
                Scanner input =new Scanner(s);
                while(input.hasNext()){
                    String text=input.nextLine();
                    [color="#FFFF00"]NGram ngram=new NGram(text,2);[/color]

                    for(int i=0;i<a.length;++i){
                        if(a[i].equals(word)){
                            count++;
                        }
                    }
                }

            } catch (SQLException ex) {
            Logger.getLogger(Freq1.class.getName()).log(Level.SEVERE, null, ex);
        }

        // String word=request.getParameter("word");

        String  result1=Integer.toString(result);
        String  count1=Integer.toString(count);
        request.setAttribute("result1", count1);
        RequestDispatcher view = request.getRequestDispatcher("result.jsp");
        view.forward(request, response);
    }

    /**
    * Returns a short description of the servlet.
    *
    * @return a String containing servlet description
    */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// &lt;/editor-fold&gt;
}

I import the library java.lang.Object but it is not defined in my code then how can I make the NGram class defined?

Is This A Good Question/Topic? 0
  • +

Replies To: using ngram class in servlet code

#2 RCR  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 7
  • View blog
  • Posts: 33
  • Joined: 04-July 12

Re: using ngram class in servlet code

Posted 25 July 2012 - 09:10 AM

I'm not sure if I understand..Java.lang.Object is the base class for all objects in java? Why would you need to import it?
Was This Post Helpful? 0
  • +
  • -

#3 demongill  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 14
  • Joined: 09-January 09

Re: using ngram class in servlet code

Posted 26 November 2012 - 03:07 AM

i dont find on google this ngram library u talked about..
btw i check ur code and yet this NGram class had been imported..

try to add this sentence

import where*.this*.class*.of*.NGram


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1