Java Classes and JSP`s (urgent)
hi, my question is:
How can i invoke normal java classes` methods using Jsp`s for this??, is it possible??, if it is, then how do you do this, and where do you have to put the java classes in order to find them from a jsp.
thanks
Hi,
You can access normal java classes in JSP pages. You have to import them in the header like this:
<%@ page language="java" import="//your java class file with package"%>
or if u r using java beans, then use the <usebean> tag. Put the java classes in the classes directory. Which server u r using? If it is JWS, then u have a specified classes directory, where u have to put all the class files along with their packages. Hope this will help.
atanu.
Similar Messages
-
Ordinary java class and jsp page
hi i want to use some java class(not javabean ) in my jsp . how do i import them and use them?
You can just import the package into your JSP, and access it like any other class of the Standard Java API that you access.
fun_one -
Hi everyone,
I build a class in java, and now i wanna use this class in my jsp file.
I put that class into web-inf/classes in Apache Tomcat, but don't work.... Anyone can help me?
Greetings!Put the class with its package such as com.sun.ejb.MyClass
-- > /WEB-INF/classes/com/sun/ejb/MyClass.class
then use it
http://www.skillipedia.com -
Passing vector between java class and jsp page
Hi,
I think this is similar to the last post but anyways maybe somebody can help us both out bontyh.....I am getting an error saying undefined variable or class when i try to access a Vector which was returned in a class.
Anyways anyone got any ideas?Maybe if you give some more information...
-
Using java class and variables declared in java file in jsp
hi everyone
i m trying to seperate business logic form web layer. i don't know i am doing in a right way or not.
i wanted to access my own java class and its variables in jsp.
for this i created java file like this
package ris;
import java.sql.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class NewClass{
public static void main(String args[]){
Connection con = null;
ResultSet rs=null;
Statement smt=null;
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
con=DriverManager.getConnection("jdbc:mysql:///net","root", "anthony111");
smt=con.createStatement();
rs= smt.executeQuery("SELECT * FROM emp");
while(rs.next()){
String str = rs.getString("Name");
}catch( Exception e){
String msg="Exception:"+e.getMessage();
}finally {
try {
if(con != null)
con.close();
} catch(SQLException e) {}
}next i created a jsp where i want to access String str defined in java class above.
<%--
Document : fisrt
Created on : Jul 25, 2009, 3:00:38 PM
Author : REiSHI
--%>
<%@page import="ris.NewClass"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!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=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1><%=str%></h1>
</body>
</html>I wanted to print the name field extracted from database by ResultSet.
but it gives error cannot find symbol str.
please help me to find right way to do this.
i am using netbeans ide.Very bad approach
1) Think if your table contains more than one NAMEs then you will get only the last one with your code.
2) Your String is declared as local variable in the method.
3) You have not created any object of NewClass nor called the method in JSP page. Then who will call the method to run sql?
4) Your NewClass contains main method which will not work in web application, it's not standalone desktop application so remove main.
Better create an ArrayList and then call the method of NewClass and then store the data into ArrayList and return the ArrayList.
It should look like
{code:java}
package ris;
import java.sql.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class NewClass{
public static ArrayList getNames(){
Connection con = null;
ResultSet rs=null;
Statement smt=null;
ArrayList nameList = new ArrayList();
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
con=DriverManager.getConnection("jdbc:mysql:///net","root", "anthony111");
smt=con.createStatement();
rs= smt.executeQuery("SELECT * FROM emp");
while(rs.next()){
nameList.add(rs.getString("Name"));
return nameList;
}catch( Exception e){
String msg="Exception:"+e.getMessage();
</code><code class="jive-code jive-java"><font>return nameList;</code><code class="jive-code jive-java">
}finally {
try {
if(con != null)
con.close();
} catch(SQLException e) {}
</code><code>return nameList;</code>
<code class="jive-code jive-java"> } -
Jsp Page session vaiable to java class and vise versa
Hi to all,
I am new to jsp, i have to programs, one jsp page and another java class. in jsp page i get the user data from html form and put the id in session. here i have to call the session vaiable to my java class where it (variable)initialize a file name.
and same i have to call the java class to jsp page which insert statements to sql server,
Please Help Me.//My Java Class file
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import javax.servlet.http.HttpSession;
import java.sql.Statement;
public class StuInfo extends Object {
//main method begins execution of Java application
public static void main (String args[]){
String StuFile = "C://"+iD+".txt"; // Here i have to get the session varaible.(ID)
try {
In my jsp Page i initilized session as
session.setAttribute("ID",StuId);
I am not able to understand where i have to declear the HTTPSession#getAttribute("ID"); -
Difference b/w Java Class and Bean class
hi,
can anybody please tell me the clear difference between ordinary java class and java Bean class. i know that bean is also a java class but i donno the exact difference between the both.
can anybody please do help me in understanding the concept behind the bean class.
Thank u in advance.
Regards,
FazlinaWhile researching this question, I came across this answer by Kim Fowler. I think it explains it better than any other answer I have seen in the forum.
Many thanks Kim
Hi
Luckily in the java world the definition of components is a little
less severe than when using COM (I also have, and still occasionaly
do, worked in the COM world)
Firstly there are two definitions that need to be clarified and
separated: JavaBean and EnterpriseJavaBean (EJB)
EJB are the high end, enterprise level, support for distributed
component architectures. They are roughly equivalent to the use of MTS
components in the COM/ COM+ world. They can only run within an EJB
server and provide support, via the server, for functionality such as
object pooling, scalability, security, transactions etc. In order to
hook into this ability EJB have sets of interfaces that they are
required to support
JavaBeans are standard Java Classes that follow a set of rules:
a) Hava a public, no argument constructor
b) follow a naming patterns such that all accessor and modifier
functions begin with set/ get or is, e.g.
public void setAge( int x)
public int getAge()
The system can then use a mechanism known as 'reflection/
introspection' to determine the properties of a JavaBean, literally
interacting with the class file to find its method and constructor
signatures, in the example above the JavaBean would end with a single
property named 'age' and of type 'int' The system simply drops the
'set' 'get' or 'is' prefix, switches the first letter to lower case
and deduces the property type via the method definition.
Event support is handled in a similar manner, the system looks for
methods similar to
addFredListener(...)
addXXXListener
means the JavaBean supports Fred and XXX events, this information is
particularly useful for Visual builder tools
In addition there is the abiliity to define a "BeanInfo' class that
explicitly defines the above information giving the capability to hide
methods, change names etc. this can also be used in the case where you
cannot, for one reason or another, use the naming patterns.
Finally the JavaBean can optionally - though usually does - support
the Serializable interface to allow persistence of state.
As well as standard application programming, JavaBeans are regularly
used in the interaction between Servlets and JSP giving the java
developer the ability to ceate ojbect using standard java whilst the
JSP developer can potentially use JSP markup tags to interact in a
more property based mechanism. EJB are heaviliy used in Enterprise
application to allow the robust distribution of process
HTH.
Kim -
How to load java class from jsp page?
hi all!
Does anyone know how to load java class from jsp page?
I try to load java class from jsp page.
Is it possible to load java class fom jsp page?
thanks and have a good day!What I mean is How to load/open java class file from jsp page?
I think we can open Applet from jsp page by using
<applet code=helloApplet.class width=100 height=100>
</applet>
but, how to open java class which is an application made by Frame?
thanks and have a good day -
Calling java class from jsp page
Dear Friends.
I wrote jsp page and java class.
Am calling java class from jsp page. after processing result,
I have to refresh jsp page from java class.
processing time may take 5 minutes or 1 minute etc. that depends on user.
Can It be possible ? if possible , How ?Ok, I get a very strange error now:
org.apache.jasper.JasperException: Unable to compile class for JSPerror: An error has occurred in the compiler; please file a bug report (http://java.sun.com/cgi-bin/bugreport.cgi).
What is this??? Anyone? -
b font color ='red' Java JDBC and Oracle DB URGENT HELP PLEASE /font /b
Hello, I am a newbie. I'm very interested in Java in relation to JDBC, Oracle and SAP.I am trying to connect to an Oracle DB and I have problems to display the output on the consule in my application. What am I doing wrong here . Please help me. This is my code: Please Explain
import java.sql.*;
import java.sql.DriverManager;
import java.sql.Connection;
public class SqlConnection {
public static void main(String[] args) {
Class.forName("oracle.jdbc.driver.OracleDriver"); //Loading the Oracle Driver.
Connection con = DriverManager.getConnection
("jdbc:orcle:thin:@34.218.5.3:1521:ruka","data","data"); //making the connection.
Statement stmt = con.createStatement ();// Sending a query to the database
ResultSet rs = stmt.executeQuery("SELECT man,jean,test,kok FROM sa_kostl");
while (rs.next()) {
String man = rs.getString("1");
String jean = rs.getString("2");
String test = rs.getString("3");
String kok = rs.getString("4");
System.out.println( man, jean, test,kok );//here where my the
//compiler gives me errors
stmt.close();
con.close();
}<b><font color ='red'>Java JDBC and Oracle DB URGENT HELP PLEASE</font></b>Too bad your attempt at getting your subject to have greater attention failed :p
-
Hi frnds i want to help in servlet,java bean and JSP
hi friends i'm right now in M.SC(IT) and i want to do project in SERVLET,,JAVA BEANS and JSP ,
so pls give me a title about that
NOTE: I develop a project in group(2 persons there)
my email id is : [email protected] , [email protected] , [email protected]You cannot pair your iPod to a cell phone, so forget about it.
The only way you can get free WiFi is to hang out at a Denny's, a Starbucks, or a truck stop, and I don't think your parents would approve.... -
Accessing java class in JSP on Tomcat 5.5 server
Just i want to use a java class in JSP.
Explanation in following steps :
a. MY JSP Code - SimpleBean.jsp
b. My Java file - test.java
c. Path ( Root, jdk, jre , myfiles-test.java, SimpleBean.jsp )
d. Environment Variables
e. Error Message faced
Now Brief explanation.
a. MY JSP Code :
<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*,test" errorPage="" %>
<td>
<%! test obj = new test();
obj.setAge(32); %>
<%= obj.getAge(); %>
</td>
b. My Java file - test.java
package test;
class test
private int age;
public int getAge()
return age;
public void setAge(int intage)
this.age = intage;
c. Path ( Root, jdk, jre , myfiles-test.java, SimpleBean.jsp )
Tomcat Root : c:\Program Files\apache\tomcat5.5\webapps\ROOT
jdk : C:\Program Files\Java\jdk1.5.0\bin;
jre : C:\Program Files\Java\jre1.5.0\bin;
test.java : c:\Program Files\apache\tomcat5.5\webapps\ROOT\NRMS\test\test.java
SimpleBean.jsp : c:\Program Files\apache\tomcat5.5\webapps\ROOT\NRMS\test\SimpleBean.jps
d. Environment Variables :
PATH :
C:\Program Files\Java\jdk1.5.0\bin; C:\Program Files\Java\jre1.5.0\bin;
CLASSPATH :
.;C:\Program Files\Java\jre1.5.0\bin;
e. Error Message Faced : ( on accessing url http://localhost:8080/NRMS/SimpleBean.jsp )
HTTP Status 500 -
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: Unable to compile class for JSP
Generated servlet error:
The import test cannot be resolved
An error occurred at line: 26 in the jsp file: /NRMS/test/SimpleBean.jsp
Generated servlet error:
test cannot be resolved (or is not a valid type) for the field SimpleBean_jsp.obj
An error occurred at line: 26 in the jsp file: /NRMS/test/SimpleBean.jsp
Generated servlet error:
test cannot be resolved or is not a type
An error occurred at line: 26 in the jsp file: /NRMS/test/SimpleBean.jsp
Generated servlet error:
Syntax error on token(s), misplaced construct(s)
An error occurred at line: 26 in the jsp file: /NRMS/test/SimpleBean.jsp
Generated servlet error:
Syntax error on token "32", delete this token
An error occurred at line: 28 in the jsp file: /NRMS/test/SimpleBean.jsp
Generated servlet error:
Syntax error on token ";", delete this token
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:389)
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:556)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:296)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:245)
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.4 logs.
Apache Tomcat/5.5.4
Please explain where i am doing the mistake.
Thanks in advance.
Regards,
Lax.>
<%@ page contentType="text/html; charset=iso-8859-1"
language="java" import="java.sql.*,test" errorPage=""
%>Your class is test.test.The compiler wouldnt know what test is from your import.
Change import as
java.sql.*,test.test
<%! test obj = new test();
obj.setAge(32); %>The symbol '!' ? -
Hi,
How does one interact between java code and jsp page.That is, if the java code does say database connection, the web page should tell that the connection has been made,just like an application but this will work on the web server not in the console.Kindly let me know.
AsJust curious but where do these questions come from? A course you are taking or you are building something for a hobby?
If you are building some small simple web-app it's probably quicker to embed code right onto your JSP page.
There are various levels of abstracting your web-app separating display from logic from the model.
The following are techniques from simple web-apps to more complicated ones.
-Embedding script right into your JSP
-Using beans
-Using custom tags ( I think there are some standard ones now, struts seems to be a popular buzzword)
-Including a servlet to handle your requests redirect, update bean content grab info form your database and forward to a JSP. (Read up on model 2 architecture.)
To include as much detail as possible would be to write a book. Fortunately many have so I don't have to fit one in this tiny reply box.
Hope that was somewhat useful. -
I have a small hosting company and was wondering what is required to be installed on a Win2k Server to host Java Servlets and JSP pages for a client of mine?
Ah, so you just want to add a servlet engine to IIS5?
Tomcat can be used as a plugin for IIS. Check out the Tomcat FAQs - somewhere in there you should find one relating to using Tomcat as an IIS plugin. They're far more comprehensive than I could ever hope to be on the matter! -
Hello,
There is a way to distribute the Mysql db files with yout java application without need to install Mysql in the computer, like in access, you just copy the .mdb file with your java class and create a conection to it.
Thank YouNo. If you want to do that you should just use Access. mySQL files will not work without the mySQL server.
Maybe you are looking for
-
Dear All, Can we copy the terms of payment from Purchasing info record in PO instade of Vendor master. My requirement is that client want to maintain terms of payment as per Vendor - Material combination in Purchasing info record and same should be a
-
Cannot Install Windows 7 with AHCI mode
Hello, Having just submitted a support ticket to MSI, I was curious to see if anyone else has experienced a similar issue or may be able to suggest a possible resolution. I recently purchased a MSI Z87-G41 PC Mate for an htpc build. I've ran into an
-
When I do a manual refresh on certain sites like NY Times or CNN, or when sites like NYT periodically push an update through, the updates won't stop loading. It's as though the update never completes. The rotating circle icon on the affected tab just
-
What is the best soundcard for Linux?
What soundcard would you recommend to buy? I was thinking that Audigy is best choice, but then I looked on ALSA website, and found out that most of Audigy is not supported or mostly unsupported (lack of capture?!). Currently I use SB Live 1024, I wan
-
Pragha: I can't play a streaming internet radio link
I want to play an internet radio from this link: http://loudcity.com/stations/death-fm/ But I keep getting an error "missing Gstreamer plug-in" I have most of the plug-ins already installed so I don't understand why its not playing. All of my other m