How to call a function defined in a JSP file into a servlet?
Hi
I have defined a JSP file with some functions in it. I am including this JSP file into other JSP files so that these functions can be used. Now is there soe way, that I can include this file in a servlet as well and use the defined functions in the servlet as well.
Thanks and Regards
Vikram
I assume you have a function with OUT arguments because you need to return at least two distinct things from this function? The functions return value and this OUT argument, too. Right? For the sake of argument, let's say that you're trying to return a VARCHAR2 value and a NUMBER value from this function.
Assuming that you cannot just wrap your existing function with a function that does not have OUT arguments, the first idea that pops to mind is to create an Oracle8 type that looks like:
CREATE TYPE MYREC AS OBJECT (V VARCHAR2(80), N NUMBER);Then you could rewrite your function to return an instance of this MYREC type instead of having one return value and one OUT parameter.
Then create a BC4J domain for this Oracle8 type (which will mimic its nested structure), and then you can just select the value straight-away in your view object.
I just tried this idea with 9.0.2 production and it works.
The Domain you create will have getV() and getN() accessors on it so you can get at the nested values in the MyRec domain "record" structure.
The other way would involve building a programmatic view object that sources the data for your VO programmatically. If I think of anything else I'll post something here.
Similar Messages
-
How to call GOS(Generic Object service) attachment ( BMP file ) into SAP
How to call GOS(Generic Object service) attachment ( BMP file ) into SAP script
Example: MM02 Service object there attaching the bmp file the same file i need to call script based on the material number
Please provide the procedure and coding.
Thanks in advance
RajuHi,
The following link may be useful to u.
help.sap.com/printdocu/.../BCSRVOBS.pdf -
How to call a function defined inside a module loader
I wanna know...the method of calling a function defined
inside a module loader component?
Th
<mx:ViewStack id="myViewStack" >
<mx:Canvas id="Mgmt1">
<mx:Label text="Gopher"/>
</mx:Canvas>
<mx:Canvas id="Mgmt2" >
<mx:Label id="gopherlbl" top="-2" left="0"
height="40"/>
<CustomComp:MgmtGrid id="ManageCom"/>
</mx:Canvas>
<mx:Canvas id="Admin">
<mx:ModuleLoader id="adminModule" url="{adminModUrl}"
width="100%" height="100%" />
</mx:Canvas>
where adminModUrl="admin.swf";
Thru the MangeCom id reference,I am able to call the fucntion
defined inisde the CustomComponent File MgmtGrid...But I am unable
to call the funciton defined inside adminModule
ModuleLoader...(using id reference).Anyone pls suggest a solution
for this..Ensure the module is loaded before calling the method in
particular if you are calling it at the initialization of your
app. -
How to call a function from Java to JSP
Hello,
I have a question about using tags.
I have a java file,which has a function. Now I want to call this function into my JSP page.
I'm using JSP 1.2 and TOMCAT 4.1 with Java2 SDK.
I search through the web and find a method to do this.Bu it requires JSP 2.0
But I try that in my machine(using JSP 1.2).It gives an error:
Did you know what is the error? Or is there any method to call a function into my JSP page?
Please, help me to solve this.
Here are my codes(part of them)
UserPassword.java file
package data;
import java.io.*;
import java.sql.*;
import java.util.*;
import javax.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class UserPassword
public static String verify(String username,String password){
// some codes
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE taglib
PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN"
"http://java.sun.com/j2ee/dtd/web-jsptaglibrary_1_2.dtd">
<taglib>
<tlib-version>1.0</tlib-version>
<jsp-version>1.2</jsp-version>
<short-name>simple</short-name>
<uri>http://jakarta.apache.org/tomcat/HRM/WEB-INF/lib</uri>
<description>
A tab library for the login
</description>
<function>
<description>verify username and password</description>
<name>verify</name>
<function-class>data.UserPassword</function-class>
<function-signature>String verify(java.lang.String,java.lang.String)
</function-signature>
</function>
</taglib>I put this file into the webapps/HRM/WEB-INF/lib folder
Here is my JSP file.
<%@ page language="java" %>
<%@ page import="data.UserPassword" %>
<%@ page session="true" %>
<%@ taglib prefix="login" uri="/WEB-INF/lib/LoginVerify.tld" %>
<jsp:useBean id="useraccount" class="data.UserPassword"/>
<jsp:setProperty name="useraccount" property="*"/>
<%
String status = UserPassword.verify(String username,String password);
String nextPage = "MainForm.jsp";
if(status.equals("InvalidU")) nextPage ="InvalidUserName.jsp";
if(status.equals("InvalidP")) nextPage ="InvalidPassword.jsp";
if(status.equals("main")) nextPage ="MainForm.jsp";
%>
<jsp:forward page="<%=nextPage%>"/>
Here is the error:
org.apache.jasper.JasperException: XML parsing error on file /WEB-INF/lib/LoginVerify.tld: (line 18, col -1): Element "taglib" does not allow "function" here.
at org.apache.jasper.xmlparser.ParserUtils.parseXMLDocument(ParserUtils.java:189)
at org.apache.jasper.compiler.TagLibraryInfoImpl.parseTLD(TagLibraryInfoImpl.java:247)
at org.apache.jasper.compiler.TagLibraryInfoImpl.(TagLibraryInfoImpl.java:183)
at org.apache.jasper.compiler.Parser.parseTaglibDirective(Parser.java:354)
at org.apache.jasper.compiler.Parser.parseDirective(Parser.java:381)Please, help me to solve this trouble.
Thanks.Yes. As serlank showed, you can just call the function easily in scriptlet tags
However the whole point of a tag library is to avoid the use of scriptlets.
Seeing as you can't use functions, is just to do it as a standard tag.
ie in your jsp
<login:verify name="<%= userName %>" password = "<%= password %>" resultVar = "status"/>
<c:choose>
<c:when test="${status == 'InvalidU'}">
<c:set var="nextPage" value="InvalidUserName.jsp"/>
</c:when>
<c:when test="${status == 'InvalidP'}">
<c:set var="nextPage" value="InvalidPassword.jsp"/>
</c:when>
</c:choose>In your case, this tag in the tld would possibly look something like this.
You would then have to write a tag handler class that would call the function you want.
<tag>
<name>verify</name>
<tagclass>com.tags.login.Verify</tagclass>
<teiclass>com.tags.login.VerifyTEI</teiclass> (if required)
<bodycontent>JSP</bodycontent>
// name attribute
<attribute>
<name>name</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
// password attribute
<attribute>
<name>password</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
// result variable to return a response from the tag.
<variable>
<name-from-attribute >resultVar</name-from-attribute >
<variable-class>java.lang.String</variable-class>
<declare>true</declare>
<scope>AT_END</scope>
</variable>
</tag>Hope this helps some, and doesn't confuse too much :-)
Cheers,
evnafets -
Call the function in postgresql to jsp
again i'm a newbie of jsp.. i just wanna know how to call the function in postgresql to jsp.. how to code it?... thanks in advance
<%@ page contentType="text/html;charset=windows-1252" import="java.sql.*"%>
<%
try
Class.forName("org.postgresql.Driver").newInstance();
Connection con = DriverManager.getConnection("jdbc:postgresql://localhost:5432/TESTDB","postgres","");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("select catalog('catalog1') from catalog");
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>untitled</title>
</head>
<body>
<%
while(rs.next()){
out.println(rs.getString(1)+"<br>");
%>
</body>
</html>
<%
}catch (Exception ex)
ex.printStackTrace();
%>
CREATE or Replace FUNCTION catalog(varchar) RETURNS catalog
AS $$ SELECT title FROM catalog WHERE catalogid = $1 $$
LANGUAGE SQL;
CREATE TABLE catalog
catalogid varchar(25) NOT NULL,
journal varchar(25),
publisher varchar(25),
edition varchar(25),
title varchar(45),
author varchar(25),
CONSTRAINT catalog_pkey PRIMARY KEY (catalogid)
WITH OIDS; -
How to call oracle function from ejb3
i'm trying to call an oracle query-function from ejb3.
The oracle function:
create or replace FUNCTION getSecThreadCount(secId in NUMBER,avai in NUMBER)
RETURN SYS_REFCURSOR is cur SYS_REFCURSOR;
m_sql VARCHAR2(250);
BEGIN
m_sql:='select count(thrId) from thread where secId='|| secid||'
and thrAvai='|| avai;
open cur for m_sql;
return cur;
END;
I'v tried several ways to call it,but all failed:
1. the calling code:
public Object getSectionThreadCount(int secId,int avai){
Query query=manager.createNativeQuery("{call getSecThreadCount(?,?) }");
query.setParameter(1, secId);
query.setParameter(2, avai);
return query.getSingleResult();
but i got the exception:
Exception in thread "main" javax.ejb.EJBException: javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not execute query; nested exception is: javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not execute query
javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not execute query
Caused by: java.sql.SQLException: ORA-06550: row 1, col 7:
PLS-00221: 'GETSECTHREADCOUNT' not procedure or not defined
ORA-06550: row 1, col 7:
PL/SQL: Statement ignored
2. the calling code:
@SqlResultSetMapping(name = "getSecThreadCount_Mapping")
@NamedNativeQuery(name = "getSecThreadCount",
query = "{?=call getSecThreadCount(:secId,:avai)}",
resultSetMapping = "getSecThreadCount_Mapping",
hints = {@QueryHint(name = "org.hibernate.callable", value = "true"),
@QueryHint(name = "org.hibernate.readOnly", value = "true")})
public Object getSectionThreadCount(int secId,int avai){
Query query=manager.createNamedQuery("getSecThreadCount");
query.setParameter("secId", secId);
query.setParameter("avai", avai);
return query.getSingleResult();
but i run into the exception:
Exception in thread "main" javax.ejb.EJBException: javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not execute query; nested exception is: javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not execute query
javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not execute query
Caused by: java.sql.SQLException: lost in index IN or OUT parameter:: 3
By the way, i have successfully called the function from hibernate. And i use oracle 11g, JBoss5 RC1.
Could anyone tell me how to call the function from EJB3?
Thanks.Here's a working model:
package.procedure: (created in example schema scott)
CREATE OR REPLACE package body data_pkg as
type c_refcursor is ref cursor;
-- function that return all emps of a certain dept
function getEmployees ( p_deptId in number
return c_refcursor
is
l_refcursor c_refcursor;
begin
open l_refcursor
for
select e.empno as emp_id
, e.ename as emp_name
, e.job as emp_job
, e.hiredate as emp_hiredate
from emp e
where e.DEPTNO = p_deptId;
return l_refcursor;
end getEmployees;
end data_pkg;
/entity class:
package net.app.entity;
import java.io.Serializable;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedNativeQuery;
import javax.persistence.QueryHint;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
@SuppressWarnings("serial")
@Entity
@Table (name="emp")
@SequenceGenerator(name = "EmployeeSequence", sequenceName = "emp_seq")
@NamedNativeQuery( name = "getEmpsByDeptId"
, query = "{ ? = call data_pkg.getEmployees(?)}"
, resultClass = Employee.class
, hints = { @QueryHint(name = "org.hibernate.callable", value = "true")
, @QueryHint(name = "org.hibernate.readOnly", value = "true")
public class Employee implements Serializable
@Id
@Column(name="emp_id")
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "EmployeeSequence")
private int id;
@Column(name="emp_name")
private String name;
@Column(name="emp_job")
private String job;
@Column(name="emp_hiredate")
private Date hiredate;
// constructor
public Employee (){}
// getters and setters
public int getId()
return id;
etc...session bean:
package net.app.entity;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import net.app.entity.Employee;
import net.app.iface.ScottAdmin;
@Stateless
public class ScottAdminImpl implements ScottAdmin
@PersistenceContext
private EntityManager entityManager;
@SuppressWarnings("unchecked")
public List<Employee> getEmployeesByDeptId(int deptId)
ArrayList<Employee> empList;
try
Query query = entityManager.createNamedQuery("getEmpsByDeptId");
query.setParameter(1, deptId);
empList = (ArrayList<Employee>) query.getResultList();
return empList;
catch (Exception e)
e.printStackTrace(System.out);
return null;
}client:
package net.app.client;
import java.util.List;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import net.app.entity.Employee;
import net.app.iface.ScottAdmin;
public class ScottClient
public static void main(String[] args)
try
// create local interface
InitialContext ctx = new InitialContext();
ScottAdmin adminInterface = (ScottAdmin) ctx.lookup("ScottAdminImpl/remote");
// select employees by deptno
int deptno = 20;
List<Employee> empList = adminInterface.getEmployeesByDeptId(deptno);
// output
System.out.println("Listing employees:");
for (Employee emp : empList)
System.out.println(emp.getId() + ": " + emp.getName() + ", " + emp.getJob() + ", " + emp.getHiredate());
catch (NamingException e)
e.printStackTrace(System.out);
}Basically you just ignore the refcursor outbound parameter.
This is a stored function, have yet to try outbound refcursor parameters in stored procedures...
Edited by: _Locutus on Apr 2, 2009 2:37 PM -
How to call userdefined function in JPA?
Hi,
Please share some sample code on how to call an User defined oracle function in JPA.
I tried in this way:
Query q = em.createNativeQuery("CALL Datbaseschemaname.GetEstimateID(?)");
q.setParameter(1, "NEW");
String result = (String)q.getSingleResult();
GetEstimateID is my function name.
I got the below exception:
6:22:44,246 INFO [STDOUT] Hibernate: CALL Datbaseschemaname.GetEstimateID(?)
16:22:44,266 WARN [JDBCExceptionReporter] SQL Error: 6576, SQLState: 65000
16:22:44,266 ERROR [JDBCExceptionReporter] ORA-06576: not a valid function or procedure name
16:22:44,266 ERROR [STDERR] javax.ejb.EJBException: javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not execute query
Thanks.
Edited by: Java_sunny on Jun 1, 2008 4:58 PMHi ,
can you some one help me please..below is snippet:-
String sql = "SELECT oracleFunctionName(?1,?2) FROM DUAL";
Query res = (Query)entitymanager.createNativeQuery(sql)
.setParameter(1, new String("xxx"))
.setParameter(2, new String("yy"));
I dont want to use Select and Dual key words in my sql because I am not able to modified the record inside the db -
How to call a function in a class from the main timeline?
Hey Guys
I have a project in Flash with four external AS files, which are linked to items in the library using AS linkage.
What I want to do is call a function in one of these files from the main timeline, how would I go about doing this? I'm not currently using a document class, most of the code is in Frame 1 of the main timeline.
Thanks// change type to the class name from the instance
ClassNameHere(this.getChildByName('instance_name')).SomeFunction(); -
How to call javascript function from PL/SQL procedure
Can anybody advice me how to call javascript function from PL/SQL procedure in APEX?
Hi,
I have a requirement to call Javascript function inside a After Submit Process.
clear requirement below:
1. User selects set of check boxes [ say user want to save 10 files and ticks 10 checkboxes]
2. user clicks on "save files" button
3. Inside a After submit process, in a loop, i want to call a javascript function for each of the file user want to save with the filename as a parameter.
Hope this clarify U.
Krishna. -
How to call java function from PL/sql in oracle applications
I am trying to call a java function from plsql procedure. Can any one explain how to call java function, and in which directory I have to store my java function in oracle applications. Do I need to register that java function from Application developer.
Thanks
Kranthihttp://www.oracle.com/technology/tech/java/jsp/index.html
Good Luck,
Avi. -
How to call stored function in my jsp
how to call stored function in my jsp?
please give me a example.Hi,
think we need mor einformation, like JDeveloper release and the how you do access the database (JDBC, BC4J, EJB,ADF...)
Frank -
How can call a function module(RFC)in one server to another sever in my rep
How can call a function module(RFC)in one server to another sever in my report program.
What i am know whenever rfc enabled immediately radio button checks then only it will come.
please justify.Syntax
CALL FUNCTION func DESTINATION dest [EXPORTING p1 = a1 p2 = a2 ...]
[IMPORTING p1 = a1 p2 = a2 ...]
[CHANGING p1 = a1 p2 = a2 ...]
[TABLES t1 = itab1 t2 = itab2 ...]
[EXCEPTIONS [exc1 = n1 exc2 = n2 ...]
[system_failure = ns [MESSAGE smess]]
[communication_failure = nc [MESSAGE cmess]]
[OTHERS = n_others]].
http://help.sap.com/saphelp_47x200/helpdata/en/22/042537488911d189490000e829fbbd/frameset.htm -
How to call java function in javascript
Hello Everyone,
Can anyone tell me solution that:
How to call java function in javascript?
Thanks,
VIDsYou can't since Java is running on the server and javascript is running in the browser long after the Java side of things has finished executing. Assuming you're not talking about an applet here.
But you can make calls back to the server through Ajax. All you need is something like a servlet on the receiving end which you can invoke through Ajax; from that point you can execute any Java code you want. -
How to call a function having OBJECT type as Return type
Hi,
I've the following function returning OBJECT type.
Pease advice me how to call this function
CREATE OR REPLACE TYPE GET_EMP_OBJ is object
( emp_name varchar2(50) ,
mgr_id number,
dept_id number
CREATE OR REPLACE FUNCTION get_emp(P_emp_no NUMBER )
RETURN GET_EMP_OBJ IS
t_emp_info GET_EMP_OBJ ;
v_ename EMP.ename%TYPE;
v_mgr EMP.mgr%TYPE ;
v_deptno EMP.deptno%TYPE;
v_ename1 EMP.ename%TYPE;
v_mgr1 EMP.mgr%TYPE ;
v_deptno1 EMP.deptno%TYPE;
BEGIN
FOR rec IN ( SELECT ename , mgr , deptno
FROM emp )
LOOP
v_ename := rec.ename ;
v_ename1 := v_ename1||'|'||v_ename ;
v_mgr := rec.mgr ;
v_mgr1 := v_mgr1||'|'||v_mgr ;
v_deptno:= rec.deptno;
v_deptno1 := v_deptno1||'|'||v_deptno ;
END LOOP ;
t_emp_info := GET_EMP_OBJ (v_ename,v_mgr,v_deptno ) ;
RETURN t_emp_info ;
EXCEPTION WHEN OTHERS THEN
DBMS_OUTPUT.put_line ('Error'||SQLCODE||','||SQLERRM ) ;
END;The above function got created successfully.
And i'm confused how to call this functions. I tried like below but didn't work
DECLARE
t_emp_info_1 GET_EMP_OBJ ;
BEGIN
t_emp_info_1 := get_emp(7566) ;
for i in 1..t_emp_info_1.COUNT
LOOP
DBMS_OUTPUT.put_line ('Values are'||i.emp_name ) ;
END LOOP;
END;SQL> CREATE OR REPLACE TYPE GET_EMP_OBJ is object
2 ( emp_name varchar2(50) ,
3 mgr_id number,
4 dept_id number
5 );
6 /
Type created.
SQL> ed
Wrote file afiedt.buf
1 CREATE OR REPLACE FUNCTION get_emp(empno NUMBER )
2 RETURN GET_EMP_OBJ IS
3 t_emp_info GET_EMP_OBJ ;
4 BEGIN
5 begin
6 select get_emp_obj(ename, mgr, deptno) into t_emp_info
7 from emp
8 where empno = get_emp.empno;
9 exception
10 when no_data_found then
11 t_emp_info := new get_emp_obj(null,null,null);
12 end;
13 return t_emp_info;
14* END;
SQL> /
Function created.
SQL> set serverout on
SQL>
SQL> declare
2 t_emp_info GET_EMP_OBJ ;
3 BEGIN
4 t_emp_info := get_emp(7566);
5 DBMS_OUTPUT.put_line ('Values are: '||t_emp_info.emp_name||', '||t_emp_info.mgr_id||', '||t_emp_info.dept_id);
6 END;
7 /
Values are: JONES, 7839, 20
PL/SQL procedure successfully completed.
SQL> -
How to call a function every 45 minutes?
Hi..
How to call a function after 45 minutes evry day..
That function returns a value.
Which is best? Thread or using timestamp?
RegardsHello Joe,
I heard of this website, gurgle something, that actually let's you put in words like "java" and "scheduling" and it will spit out other websites that mention these terms. Fascinating stuff, hopefully I'll find the time to test it someday soon..
Lucky for you I have an article discussing solutions to your problem in my bookmarks:
http://www.ibm.com/developerworks/web/library/j-schedule.html
With kind regards
Ben
Maybe you are looking for
-
How can I fix my iPod if it won't load any app?
My iPod won't load any apps and if it does I will get kicked out of the app within 20 seconds. I've read that I should just try restarting it by holding the home and power button until it shuts off, but my power button is stuck. The other thing I've
-
ITunes store does not match that of the gift card...
I got a gift card from Germany and live in Switzerland. Apple support recommends to give it away to somebody living in Germany or so... Not very helpfull ! In internet there are some blogs how to install an account in a foreign country, but you have
-
Multipart mime in XI for attachments?
Hi, I am not big on all the terminology, so please me nice But in a discussion for B2B with a marketplace, the subject of recieving attachments came up and he asked if we could accept our attachments in Multipart mime. Now I know Binary and text of t
-
Wireless failure on Satellite T110-10X witn Windows 7 64-bit
Done initial boot/setup while connected via Ethernet cable. Installed other AV, other productivity suite, etc. apps, and installed all Microsoft Updates. Then switched to WLAN, and disaster striked. WLAN stays connected for few seconds and then stops
-
Exception Starting Invocation Service
I'm seeing the following exception during testing. It isn't clear to me what the problem is. Please let me know what further information you need to disgnose it. Thanks, Tom 2006-05-05 11:24:21,276 ERROR [atlassian.confluence.util.XWorkTransactionInt