How to use class in JSP file?

Hello All,
I am new to Jsp.
In Jsp file,I used class of myself.
Why,the Constractor seems not working?
Thanks in advance.

Hi,
You can import the class in a jsp file.
Use <% page import = "">
and call that class.
If u want to import a funtion in your class, then u can insert that into scriplets like <%! ..%>
Hope u got that!
Artz

Similar Messages

  • How to use class in JSP page ? In java works in JSP not...

    Hello developers,
    I need check if URL exists.. i use this code in java.. it works fine..
    import java.net.*;
    import java.io.*;
    public class Check {
    public static void main(String s[]) {
        System.out.println(exists("http://www.google.com"));
        System.out.println(exists("http://www.thisURLdoesntexis.com"));
    static boolean exists(String URLName){
      try {
        HttpURLConnection.setFollowRedirects(false);
        // note : you may also need
        //        HttpURLConnection.setInstanceFollowRedirects(false)
        HttpURLConnection con =
           (HttpURLConnection) new URL(URLName).openConnection();
        con.setRequestMethod("HEAD");
        return (con.getResponseCode() == HttpURLConnection.HTTP_OK);
      catch (Exception e) {
           e.printStackTrace();
           return false;
    }in java all works fine.. it shows
    TRUE
    FALSE
    but i have no idea how can i implement this java code to my check.jsp page..
    i tried something like this..
    <%@ page import="java.io.*" %>
    <%@ page import ="java.net.*" %>
    <BODY>
    <%
    static boolean exists(String URLName){
      try {
        HttpURLConnection.setFollowRedirects(false);
        // note : you may also need
        //        HttpURLConnection.setInstanceFollowRedirects(false)
        HttpURLConnection con =
           (HttpURLConnection) new URL(URLName).openConnection();
        con.setRequestMethod("HEAD");
        return (con.getResponseCode() == HttpURLConnection.HTTP_OK);
      catch (Exception e) {
           e.printStackTrace();
           return false;
    String a="http://www.google.com";
    %>
    <%= exists(a)%>and i want to see in my jsp page the result.. it means that JSP page shows
    TRUE
    Thanks in advance,

    Hi there,
    One solution is to use JavaBeans and call the methods for the JavaBean from the JSP page.
    Suppose you have a JavaBean called TestConnectionBean as follows:
    package test22;
    import java.net.HttpURLConnection;
    import java.net.URL;
    import java.net.MalformedURLException;
    import java.io.IOException;
      Set the testUrl before checking if connection exists.
    public class TestConnectionBean {
        String testUrl;
        boolean connectionExists;
        public TestConnectionBean() {
        public String getTestUrl() {
            return testUrl;
        public void setTestUrl(String testUrl) {
            this.testUrl = testUrl;
        public boolean getConnectionExists() throws IOException, MalformedURLException {
            HttpURLConnection.setFollowRedirects(false);
            // note : you may also need
            //        HttpURLConnection.setInstanceFollowRedirects(false)
            HttpURLConnection con = null;
            con = (HttpURLConnection) new URL(this.testUrl).openConnection();
            con.setRequestMethod("HEAD");
            return (con.getResponseCode() == HttpURLConnection.HTTP_OK);
        public void setConnectionExists(boolean connectionExists) {
            this.connectionExists = connectionExists;
    }Then you can create a JSP page like this:
    <%@ page contentType="text/html;charset=UTF-8" language="java" %>
    <html>
      <head><title></title></head>
      <body>
      <jsp:useBean id="testConnectionBean" class="test22.TestConnectionBean"/>
      <jsp:setProperty name="testConnectionBean" property="testUrl" value="http://www.google.com" />
      <br/><br/>
      Does the connection exist for http://www.google.com : <jsp:getProperty name="testConnectionBean" property="connectionExists"/>
      <br/><br/>
      <jsp:setProperty name="testConnectionBean" property="testUrl" value="http://www.thisURLdoesntexis.com" />
      <br/><br/>
      <%-- The following will give an exception : java.net.UnknownHostException: www.thisURLdoesntexis.com since the URL doesn't exist. 
      --%>
      <%--
      Does the connection exist for http://www.thisURLdoesntexis.com : <jsp:getProperty name="testConnectionBean" property="connectionExists"/>
      --%>
      </body>
    </html>The output you see looks like:
    Does the connection exist for http://www.google.com : true
    I think it is better to handle the exceptions in the JavaBean itself, so now yyou can change the method signature of getConnectionExists , remove all exceptions from method signature but handle them with a try/catch inside the method itself.

  • HOW to use class in different file???

    hi
    I want to use other class
    and write them separately in different .java file
    but when i compile the one who call the class
    it says it cannot resolve the symbol, which is the class name I call
    Can anyone help me

    it says it cannot resolve the symbol, which is the
    class name I callYep. This is a "classpath" problem. You have to tell Java where all the class files are that you'll be using. The simplest way to do this when you're starting out is to make sure all your files are in the same directory and compile using the following command:
    javac -classpath . *.javaTake careful note of the spaces and "." after the "-classpath". This tells Java to look in the current directory for your class files (naturally, you'll need to be in the same directory as your *.java files when you run that command).
    You may also want to check out the beginner tutorials available on this site. They'll help out a bunch!
    Good luck!

  • Getting intermedia classes in jsp file

    Hi,
    I am using oracle intermedia classes in jsp file.I am importing the package 'oracle.ord.im' , and when running it is telling that the package is not available.
    I installed intermedia with oracle 10g, and i am using tomcat server,i don't know why it is saying that package is not availabe.
    can any one tell me how to access that package in a jsp file

    See my reply to your duplicate query

  • How to use javap with jar files ?

    how to use javap with jar files ?
    thanks

    As long as the jar is on the class path, your gold. So,
    javap -classpath myjar.jar mypackage.MyClass
    Chuck

  • Help me!! How to use JavaScript with JSP ??

    I am using JDeveloper and I created a screen in JSP which uses a bean for database connectivity and retriving info onto the page.
    The page has a ListBox where list items are populated from the database.My requirement is
    whenever the list is changed the page shuold be refreshed with the selected item info.
    I tried to use 'JavaScript' for triggering the event with 'onChange' event of the ListBox.But the event is not getting invoked. I think JavaScript is not working with JSP.
    Please help me with how to Use javaScript with JSP or any other alternative where I can meet my requirement.
    I have one more question...I have gone through the JSP samples in OTN and I am trying do download the sample 'Travel servlet' which show list of countries...etc
    I have also gone through the 'readme' but I don't know how to extract .jar file.
    I would be great if you could help me in this.
    Thanks!!
    Geeta
    null

    We have a similar need. We have used Cold Fusion to display data from Our Oracle Database. We have a simple SElect Box in HTML populated with the oracle data. When someone selects say the State of Pennsylvania. then we have an On change event that runs a Javascript to go get all the cities in Pennsylvania.
    Proble we are having is that inorder for the Javascript to work , we currently have to send all the valid data.
    Do you know of any way to dynamically query the the Oracle database in Javascript

  • How to use EJB in JSP...urgent!!!

    hello,
    i am novice programmer in EJB.
    i am using weblogic 6.1 ...
    my problem is how to use EJB in jsp page.
    my code is as follow..but its not displaying any result.
    <%@ page import="javax.naming.InitialContext,
    javax.naming.Context,
    java.util.Properties,
    firstEJB.First,
    firstEJB.FirstHome"%>
    <%
         long t1 = System.currentTimeMillis();
         System.out.println(t1);
         Properties props = new Properties();
         p.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.TengahInitialContextFactory");
         props.put(Context.PROVIDER_URL, "localhost:7001");
         Context ctx = new InitialContext(props);
         FirstHome home = (FirstHome)ctx.lookup("FirstEJB");
         First bean = home.create();
         String time = bean.getTime();
         bean.remove();
         ctx.close();
         long t2 = System.currentTimeMillis();
    %>
    <html>
         <head>
              <style>p { font-family:Verdana;font-size:12px; }</style>
         </head>
         <body>
              <p>Message received from bean = "<%= time %>".<br>Time taken :
              <%= (t2 - t1) %> ms.</p>
         </body>
    </html>
    please tell me the solution.

    Hi, I don't know if it may be the cuase of your problems, but you should narrow the Object obtained doing the lookup, like this:
    FirstHome home = (FirstHome) PortableRemoteObject.narrow(ctx.lookup("FirstEJB"), FirstHome.class);

  • How to authorize my Login.jsp file to create LoginContext, deployed in war

    I am currently doing a login process and I need to know how to give my Login.jsp file the permission to create a LoginContext. I packaged everything in a war file and deployed it to the server.
    Specifically this is the error that I am getting:
    type Exception report
    message
    description The server encountered an internal error () that prevented it from fulfilling this request.
    exception
    org.apache.jasper.JasperException: access denied (javax.security.auth.AuthPermission createLoginContext.studentportal)
         org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:384)
         org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:297)
         org.apache.jasper.servlet.JspServlet.service(JspServlet.java:247)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:860)
         sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         java.lang.reflect.Method.invoke(Method.java:585)
         org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:249)
         java.security.AccessController.doPrivileged(Native Method)
         javax.security.auth.Subject.doAsPrivileged(Subject.java:517)
         org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:282)
         org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:165)
    root cause
    java.security.AccessControlException: access denied (javax.security.auth.AuthPermission createLoginContext.studentportal)
         java.security.AccessControlContext.checkPermission(AccessControlContext.java:264)
         java.security.AccessController.checkPermission(AccessController.java:427)
         java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
         javax.security.auth.login.LoginContext.init(LoginContext.java:224)
         javax.security.auth.login.LoginContext.(LoginContext.java:403)
         org.apache.jsp.Login_jsp._jspService(Login_jsp.java:55)
         org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:105)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:860)
         org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:336)
         org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:297)
         org.apache.jasper.servlet.JspServlet.service(JspServlet.java:247)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:860)
         sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         java.lang.reflect.Method.invoke(Method.java:585)
         org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:249)
         java.security.AccessController.doPrivileged(Native Method)
         javax.security.auth.Subject.doAsPrivileged(Subject.java:517)
         org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:282)
         org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:165)
    note The full stack trace of the root cause is available in the Sun-Java-System/Application-Server logs.
    In my code in Login.jsp this is what I have at the top of the page:
    <%@ page language="Java" import="portal.*,javax.security.auth.login.*" %>
    <%
    String s = request.getParameter("loginButton");
    if (s != null) {
    out.println("The user attempted to login");
    String user = request.getParameter("username");
    String psw = request.getParameter("psw");
    AscCallbackHandler cbh = new AscCallbackHandler(user,psw);
    LoginContext ctx;
    try {
    ctx = new LoginContext("studentportal",cbh);
    } catch (LoginException  le) {
    out.println("Sorry, could NOT create context");
    }The admin page tells me that portal is deployed at location:
    ${com.sun.aas.instanceRoot}/applications/j2ee-modules/portal
    My entry in the server.policy file looks like so:
    grant codeBase "file:/home/jay/sun/Creator2_1/SunAppServer8/domains/creator/applications/j2ee-modules/portal/WEB-INF/-" {
    permission javax.security.auth.AuthPermission "createLoginContext.studentportal";
    permission javax.security.auth.AuthPermission "modifyPrincipals";
    permission javax.security.auth.AuthPermission "getLoginConfiguration";
    Which gives the error shown above
    Please help
    Message was edited by:
    jay_dawg
    Placing code tags

    java.lang.NoClassDefFoundError: org/jdom/JDOMException
         java.lang.Class.getDeclaredConstructors0(Native Method)
         java.lang.Class.privateGetDeclaredConstructors(Class.java:2357)
         java.lang.Class.getConstructor0(Class.java:2671)
         java.lang.Class.getConstructor(Class.java:1629)
         org.apache.jasper.compiler.Generator$GenerateVisitor.visit(Generator.java:1164)
         org.apache.jasper.compiler.Node$UseBean.accept(Node.java:1116)
         org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2163)
         org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2213)
         org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2219)
         org.apache.jasper.compiler.Node$Root.accept(Node.java:456)
         org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2163)
         org.apache.jasper.compiler.Generator.generate(Generator.java:3305)
         org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:198)
         org.apache.jasper.compiler.Compiler.compile(Compiler.java:295)
         org.apache.jasper.compiler.Compiler.compile(Compiler.java:276)
         org.apache.jasper.compiler.Compiler.compile(Compiler.java:264)
         org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:563)
         org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:303)
         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)
         org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:368)and following by this

  • How to use taglibs in JSP for Database access

    Hi
    Could any one please tell me how to use taglibs in JSP for Database access
    with regrds
    Jojo

    This is a sample how to connect to a MySQL database with JSTL 1.0:
    <%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" errorPage="" %>
    <%@ taglib uri="http://java.sun.com/jstl/sql" prefix="sql" %>
    <%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>JSTL MySQL</title>
    <link href="styles.css" rel="stylesheet" type="text/css" />
    </head>
    <body>
    <c:catch var="e">
    <sql:setDataSource var="datasource" url="jdbc:mysql://Your_Server_Name_Here/You_Schema_Here"
                           user="Your_Username_Here" password="Your_Password_Here"
                           driver="com.mysql.jdbc.Driver"/>
    <c:out value="datasource= ${datasource},  Class = ${driver.class}"/>
    <br />
    <br />
    <sql:query var="deejays" dataSource="${datasource}">SELECT * FROM Your_Table_Name_Here</sql:query>
    <table>
    <%-- Get the column names for the header of the table --%>
    <c:forEach var="columnName" items="${deejays.columnNames}"><th><c:out value="${columnName}"/></th></c:forEach>
    <tbody>
    <%-- Get the value of each column while iterating over rows --%>
    <c:forEach var="row" items="${deejays.rows}">
      <tr><c:forEach var="column" items="${row}">
            <td><c:out value="${column.value}"/></td>
          </c:forEach>
      </tr>
    </c:forEach>
    </tbody>
    </table>
    </c:catch>
    <br />
    <br />
    <c:if test="${e!=null}"><span class="error">Error</span>�
      <c:out value="${e}" />
    </c:if>
    </body>
    </html>And this thread might help you:
    http://forum.java.sun.com/thread.jspa?threadID=639471&tstart=44

  • How to use datagrid in jsp ?

    Hi All ,
    Can any body let me know , how to use datagrid in jsp pages .I have downloaded the taglibs-datagrid.jar file and taglibs-datagrid.tld. I have saved the .jar File in the WEB-INF/lib and .tld to the WEB-INF directories.
    I wrote a program that is getting a collection from the request and i just want to display the objects in the datagrid.Please help me out of this problem.It's better to explain with example. Waiting for a response.
    Regards,
    Rakesh

    Why do you want to use threads to do this ??
    If you write a message and do a redirection, the message will be displayed until the other page will be loaded into the browser...
    I already launched a thread from a JSP but it was for a four hour process where the user can close his browser windows.

  • How can i access the jsp file in a asp file

    Hi every one..
    we have two projects one is developed in ASP and one is developed in JSP both are running in two different locations.
    now i want to include a jsp file from one project to ASP file in the other project.
    please tell me how can i insert the JSP file in ASP application.
    thanx in advance.

    Wouldn't that be an ASP question for an ASP forum?

  • How to use JOptionPane in jsp, instead of javascript message alert box?

    HI,
    How to use JOptionPane in jsp,
    instead of javascript "message alert box"?
    I hate javascript,
    I'd like to only use java in jsp. don't use javascript.
    javascript is client side,
    jsp is server side. i know that.
    how to... instead of javascript box?
    how to use ... message box in webpage?
    don't use applet,,,, don't use javascript,,,
    hm...zzzZzz
    I hate javascript..T.T
    <SCRIPT language=JavaScript>
    alert("hate javascript");
    </SCRIPT>
    ===>>>>
    In this way,,
    JOptionPane.showOptionDialog(null,"I love java")
    I'd like to only use jsp and java and html...in webpage.
    don't use javascript....
    Why? don't sun provide message box in jsp, instead of javascrip box?
    Why?
    Edited by: seong-ki on Nov 4, 2007 8:38 PM

    Drugs are bad, m'kay?

  • How to use a Windows Help File (.hlp) - URGENT

    Hello!
    Can anybody tell me how to use a windows help file (.hlp) in my Java application? Is there any possiblity to reference a specific topic (by Help Context-ID)?
    Thanks in advance,
    Phil

    try calling the Runtime.exec() method
    pass the paramter String as <filename>.hlp
    i donno about the context
    regards
    rohan

  • How to use cookies in jsp

    Hi all,
    I'm new to jsp, please let me know how to use cookies with jsp.
    I have three web applications, in run time I have to switch from one application to another application based on single login page. I have taught cookies are one of the solution. But while I'm googling I unable to get such a good material.
    please give some examples,
    Thanks in advance.
    achchayya

    Read a cookie in jsp
    HttpSession session = request.getSession();
    Cookie cookie_session = getCookie(request, "COOKIENAME");
              if (cookie_session == null) {
                   sesID = session.getId();
              } else {
                   sesID = cookie_session.getValue();
              }or
    get all cookie in the browser
    This gets all the cookies and according to the cookie name given u can get the cookie value
    Cookie[] cookies = request.getCookies();
              if (cookies != null) {
                   for (int i = 0; i < cookies.length; i++) {
                        if (cookies.getName().equals(cookieName))
                             return cookies[i];
                   }but i am not sure if this works for ur requirement try and see                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • How to use threads in JSP???

    hello
    i want to use threads with JSP.
    i want to write a jsp page which will
    start 2 different threads. the 1st thread should just display a message and the second page should redirect this page to another jsp page.
    till the redirection is goin on, the message should be displayed in the browser from the 1st thread.
    i dont know actually how to use threads in JSP by implementing the Runnable insterface, if not m then how do i do it ??
    thanx
    Kamal Jai

    Why do you want to use threads to do this ??
    If you write a message and do a redirection, the message will be displayed until the other page will be loaded into the browser...
    I already launched a thread from a JSP but it was for a four hour process where the user can close his browser windows.

Maybe you are looking for

  • Adobe Acrobat XI Pro - Buch einscannen und markieren

    Guten Nachmittag Ich habe ein Buch, von dem es kein eBook gibt. Ich wollte mir wichtige Seiten einscannen (.jpg) und dann diese nach Adobe PDF konvertieren und darin die wichtigen Textstellen in Adobe farbig markieren. Das geht aber leider nicht, ich

  • Player in browser

    My player associated with my browseris currently not working. I work for an online radio station and was using my bb to listen Live to the broadcast www.Kmn1061.com through the flash player on the website. Currently... I'm getting nothing! The page w

  • Controlling the frame of a mask?

    Hi gang, I have to do a bunch of masks on still portraits.  I need each portrait to be the same frame size.  I want to use masks to standardize the frame size.  In FCPX I could use the 'Crop', which is okay.  But as I was experiment with the 'mask' I

  • Document Set and WF 2013

    I have two questions: 1. Can workflow be started on Document Set (using 2013 workflow - Visual Studio) ? 2. Can Document Set be declared as Record from 2013 workflow - Visual Studio? EDIT: 3. Can Document Set be declared as Record programmatically?

  • How do i get spyware off my iCloud?

    How do I remove spyware from my iCloud?