-1

I have written a class in java: "sample.java" under the package name foo with a method

char check(String,String) 

In my Jsp page I wrote the following code:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@ page import ="foo.sample" %> 
<%@ page import="java.io.*,java.util.*,java.sql.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Insert title here</title>
    </head>
    <body>
    <%!sample obj=new sample(); %>
    <% 
    char a='n';
    String name=request.getParameter("usr");  
    String pass=request.getParameter("psw");  

    out.print("Welcome "+name);  
    out.print("pass "+pass);
    session.setAttribute("user",name); 
    a=obj.check(name,pass);
    %>

but when I run the code in server, an error is shown as follows

char() not visible

Can anyone help me with this?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Dev
  • 1
  • 1
  • 1
  • 1
    Can you share part of your code please ? – Tim Weber Jan 05 '17 at 07:53
  • 1
    Possible duplicate of [Invoking a Java Method in JSP](http://stackoverflow.com/questions/9566410/invoking-a-java-method-in-jsp) – DimaSan Jan 05 '17 at 07:53
  • see http://stackoverflow.com/questions/9566410/invoking-a-java-method-in-jsp – Scary Wombat Jan 05 '17 at 07:54
  • Use [JSTL](http://docs.oracle.com/javaee/5/jstl/1.1/docs/tlddocs/) for the purpose. You may refer [How to call parameterized method from JSP using JSTL/EL](http://stackoverflow.com/questions/7121303/how-to-call-parameterized-method-from-jsp-using-jstl-el) – Dhaval Simaria Jan 05 '17 at 08:25
  • I doubt it says "char() not visible", it is probably "char check(...) not visible" and, if so, you have to make `check()` public. – Nikos Paraskevopoulos Jan 08 '17 at 10:48

1 Answers1

0

In case the method is static public static char check(String a,String b)

<%@ page import="foo.sample" %>
<%= sample.check("aaa", "bbb") %>

If it is not static

<%@ page import="foo.sample" %>
<%= new sample().check("aaa", "bbb") %>

But, as long as this method seems to be utility method, I would recommend to make it static, if it's not yet

Anton Dovzhenko
  • 2,399
  • 11
  • 16