Invoke Java 3d from a JSP?
Hi,
I have a sample java code that invokes a Canvas3d and then invokes a 3D object.
Our project goal is to create an online application-- A JSP page which will invoke the java 3d object.
I am working on Oracle JDeveloper and OC4J server.
Currently , the application runs thru a .java file.
I want to know if it is technically possible to create a jsp page and transfer the 3d object generated by this java file onto the JSP?
I tried renaming the main method of the java file to say testMain (made it static method).
Then thru the JSP , i tried to call this testMain method.
It doesnt work.
thanks
HI
I was able to add a canvas3D to a webbrowser via an applet. I suppose you can always invoke an applet from a JSP.
Venkat
Similar Messages
-
Invoking java methods from C/C++ on the machine with different JREs
I implemented Windows NT Service instantiating JVM and invoking several java methods. Everything works but I have an issue with running the service on the machine where multiple different versions of JRE have been installed. The service is calling java methods that require JRE 1.3 or later so I wrote the code that is setting system PATH from within the service based on the configuration stored in the external file. The problem is that the service requires jvm.dll to be in the PATH prior lunching it since this library is instantiated through the implicit linking. When I put jvm.dll in the same path as the service binary I can lunch it but JNI_CreateJavaVM fails and returns -1. This happens even if JRE 1.3 is in the system PATH prior lunching the service.
Everything works if the system PATH contains references to JRE 1.3 and jvm.dll is removed from the service's directory.
I am looking for an advice on what is the proper way to deal with invoking java methods from the C/C++ executable in the environment with different versions of JRE.
Thanks, Kris.Here's a way I have done what you are asking about:
What you want to do is make all of your linking happen at runtime, rather than at compile time. This way, you can edit the PATH variable before the jvm.dll gets loaded.
Following is some code that I used to handle a dll of my own in this manner. You can decide if you want to write a "wrapper" dll, or if you find it simpler to approach the jvm.dll in this way.
// Define pointer type for DLL entry point.
typedef void JREPDLL_API (*EXECUTEREQUEST)(char*, Arguments&);
// Set up path, load dll, and pass everything off to it.
HINSTANCE javaServer = javaServer = LoadLibrary("jrepdll.dll");
if (javaServer != NULL) {
EXECUTEREQUEST executeRequest = (EXECUTEREQUEST)GetProcAddress(javaServer, "ExecuteRequest");
if (executeRequest != NULL) {
if (argc == 1)
// Execute the request.
executeRequest("-run", args);
else
// Execute the request.
executeRequest("-console", args);
Here's some code for how to edit the PATH:
// Edit the PATH environment variable so that we use our private java.
char *appendPt;
char *newPath;
char *path;
char tmp[_MAX_PATH];
// Get the current PATH variable setting.
path = getenv("PATH");
// Allocate space for an edited path setting.
if (path != NULL)
newPath = (char*)malloc((_MAX_PATH * 2) + strlen(path));
else
newPath = (char*)malloc((_MAX_PATH * 2));
// Get upper part of path to desired directories.
strcpy(tmp, filepath);
appendPt = strstr(tmp, "dbin\\jreplicator");
appendPt[0] = '\0';
sprintf(newPath, "PATH=%sjava\\jre1.2.2\\bin;%sjava\\jre1.2.2\\bin\\classic", tmp, tmp);
// Append the value of the existing PATH environment variable.
// If there is anything, append it.
if (path != NULL) {
strcat(newPath, ";");
strncat(newPath, path, (sizeof(newPath) - strlen(newPath) - 2));
// Set new PATH value.
_putenv(newPath);
free(newPath); -
How to invoke java application from ABAP
How to invoke java application from ABAP ? Suppose I needto execute a EJB wihic is running on my SAP J2EE Enigne from an ABAP Program .
Thanks,
ManishHi Manish,
did you get some further documents concerning "abap program calls ejb"?
If yes, could you please send me some informations.
Thank you for your help.
Kind regards, Patrick. -
I have Flex running on Tomcat with LCDS. On tomcat there is a JAR that has classes I'd like to use/interact with from Flex. In the simple LCDS examples they demonstrate having a Product.java class and a matching Product.as class, but the java library I am trying to use has many more classes and would take a long time to copy into Actionscript.
What is the best way to interact with the Java classes (I don't have a web service to use like in the LCDS example).I only know we can use JNI to invoke native libraries
from Java and I have never used JNI to invoke Java
libraries from native applications (C/C++ programs).
I am going to look through the tutorial you
recommended.The last tutorial. I've only fiddled with it, as it was a bitch. If you don't need to use Suns JVM, I recomend using CNI & GCJ [ http://gcc.gnu.org/java/ ], as it is much neater.
Do you mean JNI is internally implemented by C++s
Runtime.exec method?Write a small Java application which invokes the lib you want, i.e. say you want to use Strings replaceAll method (simple example I know)
class Test {
pubilc static void main( String args[] ) {
System.out.println( args[0].replaceAll( args[1], args[2] ) ) ;
}Then use c++ program to run "/path/to/java Test tast a e" . -
Invoke Java library from C/C++
Hello everyone,
Are there any approaches to invoke Java libraries from C/C++?
Thanks in advance,
GeorgeI only know we can use JNI to invoke native libraries
from Java and I have never used JNI to invoke Java
libraries from native applications (C/C++ programs).
I am going to look through the tutorial you
recommended.The last tutorial. I've only fiddled with it, as it was a bitch. If you don't need to use Suns JVM, I recomend using CNI & GCJ [ http://gcc.gnu.org/java/ ], as it is much neater.
Do you mean JNI is internally implemented by C++s
Runtime.exec method?Write a small Java application which invokes the lib you want, i.e. say you want to use Strings replaceAll method (simple example I know)
class Test {
pubilc static void main( String args[] ) {
System.out.println( args[0].replaceAll( args[1], args[2] ) ) ;
}Then use c++ program to run "/path/to/java Test tast a e" . -
How to invoke Java class from post.POST.jsp
Hi All,
I am trying to invoke a simple java method from post.POST.jsp
I am getting below exception while doing it.
org.apache.sling.api.scripting.ScriptEvaluationException: org.apache.sling.scripting.jsp.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: 32 in the jsp file: /apps/mywebsite/components/customFormAction/post.POST.jsp
The method test() is undefined for the type DatasourceUtil
29:
30: ///
31: com.day.test.datasource.DatasourceUtil dsUtil = new com.day.test.datasource.DatasourceUtilImpl();
32: dsUtil.test();
33: //dsUtil.validateLogin(request.getParameter("username"), request.getParameter("password"));
34:
35: ////
It appears to resolve the class correctly. I could run the code, if I only comment dsUtil.test();. As soon as I uncomment, it gives above error.
In the Utill I have a simple void method which will print a simple text. My package structure is as follows.
any help will be great
Tx1. In the interface [1] not the implementation[2] have u defined the method test?
2. If it is implemented, Change the bundle version in bnd file and make a new build. Then from felix console verify the latest version reflected in the bundles.
If 2 works & you are going to make lot of frequent changes then give the version as snapshot till it get stable.
[1] com.day.test.datasource.DatasourceUtil
[2] com.day.test.datasource.DatasourceUtilImpl -
Invoking BPEL Process from a JSP Page 500 Internal Server Error
Hi,
I try to invoke a BPEL Process from a JSP Page and receive the following error. I just pasted the example from the Oracle PM Developer's Guide tutorial. Previously I deployed the CreditRatingService BPEL Process.
Can anyone help me, please?
D.
Here is a sequence from my JSP / and the error I get:
String ssn = request.getParameter("ssn");
if(ssn == null)
ssn = "123-12-1234";
String xml = "<ssn xmlns=\"http://services.otn.com\">"
+ ssn + "</ssn>";
Locator locator = new Locator("default","welcome1");
IDeliveryService deliveryService =
(IDeliveryService)locator.lookupService
(IDeliveryService.SERVICE_NAME );
// construct the normalized message and send to oracle bpel process manager
NormalizedMessage nm = new NormalizedMessage( );
nm.addPart("payload", xml );
NormalizedMessage res =
deliveryService.request("CreditRatingService", "process", nm);
Map payload = res.getPayload();
out.println( "BPELProcess CreditRatingService executed!<br>" );
out.println( "Credit Rating is " + payload.get("payload") );
500 Internal Server Error
java.lang.Exception: Erstellen von "ejb/collaxa/system/DeliveryBean"-Bean nicht erfolgreich. Es wurde folgende Exception gemeldet: "javax.naming.NameNotFoundException: ejb/collaxa/system/DeliveryBean not found
at com.evermind[Oracle Containers for J2EE 10g (10.1.3.3.0) ].server.rmi.RMIServerContext.lookup(RMIServerContext.java:207)
at com.evermind[Oracle Containers for J2EE 10g (10.1.3.3.0) ].server.ApplicationContext.unprivileged_lookup(ApplicationContext.java:257)
at com.evermind[Oracle Containers for J2EE 10g (10.1.3.3.0) ].server.ApplicationContext.lookup(ApplicationContext.java:197)
at javax.naming.InitialContext.lookup(InitialContext.java:351)
at com.oracle.bpel.client.util.BeanRegistry.lookupDeliveryBean(BeanRegistry.java:279)
at com.oracle.bpel.client.delivery.DeliveryService.getDeliveryBean(DeliveryService.java:250)
at com.oracle.bpel.client.delivery.DeliveryService.request(DeliveryService.java:83)
at com.oracle.bpel.client.delivery.DeliveryService.request(DeliveryService.java:53)
at _InvokeBP._jspService(_InvokeBP.java:65)
[InvokeBP.jsp]
at com.orionserver[Oracle Containers for J2EE 10g (10.1.3.3.0) ].http.OrionHttpJspPage.service(OrionHttpJspPage.java:59)
at oracle.jsp.runtimev2.JspPageTable.service(JspPageTable.java:462)
at oracle.jsp.runtimev2.JspServlet.internalService(JspServlet.java:594)
at oracle.jsp.runtimev2.JspServlet.service(JspServlet.java:518)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
at com.evermind[Oracle Containers for J2EE 10g (10.1.3.3.0) ].server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:713)
at com.evermind[Oracle Containers for J2EE 10g (10.1.3.3.0) ].server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:370)
at com.evermind[Oracle Containers for J2EE 10g (10.1.3.3.0) ].server.http.HttpRequestHandler.doProcessRequest(HttpRequestHandler.java:871)
at com.evermind[Oracle Containers for J2EE 10g (10.1.3.3.0) ].server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:453)
at com.evermind[Oracle Containers for J2EE 10g (10.1.3.3.0) ].server.http.HttpRequestHandler.serveOneRequest(HttpRequestHandler.java:221)
at com.evermind[Oracle Containers for J2EE 10g (10.1.3.3.0) ].server.http.HttpRequestHandler.run(HttpRequestHandler.java:122)
at com.evermind[Oracle Containers for J2EE 10g (10.1.3.3.0) ].server.http.HttpRequestHandler.run(HttpRequestHandler.java:111)
at oracle.oc4j.network.ServerSocketReadHandler$SafeRunnable.run(ServerSocketReadHandler.java:260)
at oracle.oc4j.network.ServerSocketAcceptHandler.procClientSocket(ServerSocketAcceptHandler.java:239)
at oracle.oc4j.network.ServerSocketAcceptHandler.access$700(ServerSocketAcceptHandler.java:34)
at oracle.oc4j.network.ServerSocketAcceptHandler$AcceptHandlerHorse.run(ServerSocketAcceptHandler.java:880)
Message was edited by:
user603180
Message was edited by:
user603180
Message was edited by:
user603180
Message was edited by:
user603180
Message was edited by:
user603180
Message was edited by:
user603180
Message was edited by:
user603180
Message was edited by:
user603180
Message was edited by:
user603180Here is the solution:
Properties props = new Properties();
props.setProperty("orabpel.platform", "oc4j_10g");
props.setProperty("java.naming.factory.initial",
"com.evermind.server.rmi.RMIInitialContextFactory");
props.setProperty("java.naming.provider.url", "ormi://localhost/orabpel");
props.setProperty("java.naming.security.principal", "oc4jadmin");
props.setProperty("java.naming.security.credentials", "welcome1");
and several jars have to be added to the project:
Orabpel.jar , Orabpel-common.jar, oc4j*.jar,
%ANT_HOME%\lib\ant.jar;
%ANT_HOME%\lib\xercesImpl.jar;
%ANT_HOME%\lib\xml-apis.jar;
%AXIS_HOME%\lib\axis.jar;
%AXIS_HOME%\lib\axis-ant.jar;
%AXIS_HOME%\lib\commons-discovery.jar;
%AXIS_HOME%\lib\commons-logging.jar;
%AXIS_HOME%\lib\jaxrpc.jar;
%AXIS_HOME%\lib\log4j-1.2.8.jar;
%AXIS_HOME%\lib\saaj.jar;
%AXIS_HOME%\lib\wsdl4j.jar; -
Invoking BPEL process from a jsp
Hi,
I am invoking a synchronous BPEL process from a jsp.
The jsp I am using is pasted below for your reference.
createWorkOrderFFA.jsp invokes another jsp invokeWorkOrderFFA.jsp which inturn calls the BPEL process.
The code is given below.
-----------------createWorkOrderFFA.jsp starts-----------
<%@page import="com.oracle.bpel.client.Locator" %>
<%@page import="com.oracle.bpel.client.NormalizedMessage" %>
<%@page import="com.oracle.bpel.client.dispatch.IDeliveryService" %>
<html>
<head>
<title>Work Order Creation </title>
<meta http-equiv="PRAGMA" content="NO-CACHE" />
<meta http-equiv="EXPIRES" content="-1" />
<SCRIPT LANGUAGE="JavaScript">
function setfocus(){
document.generatePO.technicianName.focus();
function mypopup()
mywindow = window.open ("totalWODetails.jsp","mywindow","scrollbars=1,width=600,height=500");
mywindow.moveTo(50,50);
function DoTheCheck()
if((document.generatePO.repair.checked != true) && (document.generatePO.replacement.checked != true) &&(document.generatePO.emergency.checked != true))
alert('Please select atleast one task type for Work Order');
return false;
document.generatePO.submit();
return true;
function chkvalues(){
if( document.generatePO.additionalInfo.value == "")
alert(" Please provide additional information for tasks assigned");
document.generatePO.additionalInfo.focus();
return false;
return true;
</SCRIPT>
</head>
<body bgcolor = "#E9C2A6">
<br>
<tr cellspacing="0" cellpadding="0">
<td width="30%" align=left ><b><h2><font color="#3333CC"> </font></b></h2> </td>
</tr>
<!-- <h1 align='center'> Work Order Creation </h1> -->
<table border="1" cellspacing="0" cellpadding="0" width="80%" align=center>
<tr bgcolor=#A68064 valign=center > </tr>
<tr bgcolor=#A68064 valign==center><td valign=center > <h2 align='center'> <font COLOR="#CDCDCD" SIZE=5 FACE="sans-serif"> Field Force Automation - Work Order Creation </font></h2></td></tr>
<tr><td align=center>
<table border="0" cellspacing="0" cellpadding="0" width="100%" >
<form name="generatePO" action="./invokeWorkOrderFFA.jsp" onSubmit="return DoTheCheck()">
</tr>
<tr >
<br>
<td width="40%" align="right" > <b> <font color="black" SIZE=2 FACE="sans-serif" align="right"> Interface Type: </font> </b> </td>
<!-- <td width="2%">:</td><td><input type="text" name="SSN" maxlength=10 size=10></td> -->
<td width="60%" colspan = "2">
<SELECT NAME="interfaceType">
<OPTION VALUE="Batch"> Batch </OPTION>
<OPTION VALUE="Near Real Time"> Near Real Time </OPTION>
<OPTION VALUE="Automatic"> Automatic </OPTION>
</SELECT >
</td>
</tr>
<tr>
<td width="40%" align=left>
</td>
<td width="20%" align=left>
</td>
<td width="20%" align=left>
</td>
<td width="20%" align=left>
</td>
</tr>
<tr>
<td width="40%" align=middle><b><font color="black" SIZE=2 FACE="sans-serif" align="right"> Work Order Tasks * : </font> </b></td>
<td width="20%"><b>Maintenance</b><br>
<INPUT TYPE=CHECKBOX NAME="repair" value="repair" >repair<P>
<INPUT TYPE=CHECKBOX NAME="replacement" value="replacement">replacement<P>
</td>
<td width="20%" align=left></td></td>
</tr>
</tr>
<tr> <td width="20%">
<td width="40%" align=left> <b>Emergency</b><br><INPUT TYPE=CHECKBOX NAME="gasEmergency" value="gasEmergency">Gas Emergency<P>
</td>
<td width="20%" align=left>
</td>
<td width="20%" align=left>
</td>
<td width="20%" align=left>
</td>
</tr>
<tr>
<td width="40%" align=middle><b><font color="black" SIZE=2 FACE="sans-serif" align="right"> Additional Information: </font> </b></td>
<td width="20%"><TEXTAREA NAME="additionalInfo" COLS=40 ROWS=6></TEXTAREA>
</td>
<td width="20%" align=left>
</td>
<td width="20%" align=left>
</td>
</tr>
</tr>
<tr bgcolor=#A68064>
<td width="40%" align=left bgcolor=#A68064>
</td>
<td width="20%" align=left bgcolor=#A68064>
</td>
<td width="20%" align=left bgcolor=#A68064>
</td>
<td width="20%" align=left bgcolor=#A68064>
</td>
</tr>
<tr bgcolor=#A68064 ><td width="100%" colspan=4 align=center bgcolor=#A68064>
<input type="submit" name="submit" value="Submit Order" style="background-color: #E9C2A6;">
<input type="reset" name="reset" value="Reset Values" style="background-color: #E9C2A6;" >
<input type="button" name="btn" value=" WO Error Report" onClick="javascript: mypopup()" style="background-color:#E9C2A6;" >
</td>
</tr>
<tr bgcolor=#A68064>
<td width="40%" align=left bgcolor=#A68064>
</td>
<td width="20%" align=left bgcolor=#A68064>
</td>
<td width="20%" align=left bgcolor=#A68064>
</td>
<td width="20%" align=left bgcolor=#A68064>
</td>
</tr>
<tr bgcolor=#A68064>
<td width="50%" colspan = "4" align=left bgcolor="#A68064"> <font color="#CDCDCD"> * Indicates Mandatory fields </font>
</td>
</tr>
<tr bgcolor=#A68064> </tr>
</form>
</table>
</td></tr></table>
</table>
<br>
<!-- <marquee> <b>Wipro Technologies</b>, <br> Disclaimer : This is only a prototype model and used only for testing. </marquee> -->
<script language="JavaScript">
</Script>
</body>
</html>
-----------------createWorkOrderFFA.jsp ends-------------
-----------------invokeWorkOrderFFA.jsp starts-----------
<%@page import="com.oracle.bpel.client.Locator" %>
<%@page import="com.oracle.bpel.client.NormalizedMessage" %>
<%@page import="com.oracle.bpel.client.delivery.IDeliveryService" %>
<html>
<head>
<title>Invoke WorkOrderService </title>
</head>
<body>
<%
String interfaceType = request.getParameter("interfaceType");
String repair = request.getParameter("repair");
System.out.println("repair repair---------------------->");
String replacement = request.getParameter("replacement");
String gasEmergency = request.getParameter("gasEmergency");
String additionalInfo = request.getParameter("additionalInfo");
String woType1="Maintenance";
String woType2="Emergency";
System.out.println("before xml---------------------->");
String xml = "<hostWOApplication xmlns=\"http://services.otn.com\">"
+"<interfaceType>" + interfaceType + "</interfaceType>"
+"<Maintenance>"
+"<repair>" + repair + "</repair>"
+"<replacement>" + replacement + "</replacement>"
+"</Maintenance>"
+"<Emergency>"
+ "<gasEmergency>" + gasEmergency + "</gasEmergency>"
+"</Emergency>"
+ "<additionalInfo>" + additionalInfo + "</additionalInfo>"
+ "</hostWOApplication>";
System.out.println("Payload data ----------------------------------------->"+xml);
Locator locator = new Locator("default","bpel");
System.out.println("Before Idelivery service--------------->");
IDeliveryService deliveryService = (IDeliveryService)locator.lookupService(IDeliveryService.SERVICE_NAME );
System.out.println("After IDeliveryService data----------------------->");
// construct the normalized message and send to Oracle BPEL Process Manager
NormalizedMessage nm = new NormalizedMessage( );
nm.addPart("payload", xml );
System.out.println("Before process service--------------->");
deliveryService.request("A2", "process", nm);
System.out.println("After process service--------------->");
out.println( "<b><Font Face=Arial color=red>Work Order has been initiated!</font></b>" );
%>
<table bgColor="#E9C2A6" border="1" cellpadding="0">
<tr ><td width="100%" colspan=4 align=center >
<b>The Work Order Details could be found at this link:
<Font Face=Arial color=red><italic>Work Order Creation Details<italic></Font><b>
</tr>
</table>
</body>
</html>
-----------------invokeWorkOrderFFA.jsp ends-----------
I am getting the following error:
----------------error desc starts----------------------
Oracle BPEL Process Manager Full Cycle
An unexpected error has occurred while executing your request. This is most likely related to a defect in the Oracle BPEL Process Manager product. We apologize for the inconvenience. Please open a TAR in http://metalink.oracle.com if you are our customers. Otherwise, you can post the error to the OTN forum and we will get back to you as soon as possible.
Attachments:
Build Information:
Oracle BPEL Server version 2.2
Build: 1361
Build time: Thu Mar 17 15:51:23 PST 2005
Build type: release
Source tag: BPELPM_10_1_2_beta3_branch
Exception Message:
[java.lang.Exception]
Invalid Login. Domain not specified.
Exception Trace:
java.lang.Exception: Invalid Login. Domain not specified.
at com.collaxa.cube.fe.util.ServletUtils.getLocator(ServletUtils.java:80)
at displayInstance.jspService(_displayInstance.java:71)
at com.orionserver.http.OrionHttpJspPage.service(OrionHttpJspPage.java:56)
at oracle.jsp.runtimev2.JspPageTable.service(JspPageTable.java:347)
at oracle.jsp.runtimev2.JspServlet.internalService(JspServlet.java:509)
at oracle.jsp.runtimev2.JspServlet.service(JspServlet.java:413)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at com.evermind.server.http.ResourceFilterChain.doFilter(ResourceFilterChain.java:65)
at com.collaxa.cube.fe.DomainFilter.doFilter(DomainFilter.java:89)
at com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:649)
at com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:322)
at com.evermind.server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:790)
at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:270)
at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:112)
at com.evermind.util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:186)
at java.lang.Thread.run(Thread.java:534)
----------------error desc ends----------------------hey mgrovr..
how to ensure that my jsps are under orabpel. i m getting a javax.naming.NameNotFoundException: ejb/collaxa/system/DomainManagerBean not found exception wile invoking bpel process from jsp. I have created the jsps in Jdeveloper and i'm running it from there only.
Can u tell me a way to keep me application under orabpel -
Error Invoking Java class from Stored proc
We are getting this error while calling a stored procedure that invokes a
static function of a java class from inside Oracle 8.1.7.
ORA-29516: Aurora assertion failure: Java thread deadlock detected
ORA-06512: at "APPS.SERVICECONSUMERINVOKE", line 0
ORA-06512: at line 40
In a Toad SQL Window, when I execute the stored procedure that invokes the
java function, it executes successfully on the first attempt. When I try to
execute it again on the same SQL Window, it gives the above error. The java
class is part of a package and indirectly makes a JMS request-reply call
via other helper classes.
The same package works fine from other web containers and
unlike the Oracle JVM Aurora, the JVMs don't detect a deadlock.
Why does the Aurora throw an error?Did you try issusing a commit and then trying again in Toad SQL Window?
The advice is to contact support:
ORA-29516: Aurora assertion failure: string
Cause: An internal error occurred in the Aurora module.
Action: Contact Oracle Worldwide Support. -
Tomcat 6 Calling a Java Servlet from a JSP Page
Below is a very simple JSP Page that calls a Java Servlet. The question is given Tomcat security constraints, is it possible to call a servlet from a JSP and get the correct output without getting an error message? If so, how would you code the web.xml file?
c:\apache-tomcat-6.0.18
Under conf
catalina
localhost
HelloWorldExample.xml is directly under localhost
The application would have this directory structure:
webapps
HelloWorldExample
hello.jsp is directly under HelloWorldExample
Under HelloWorldExample
src
WEB-INF
classes
Under classes
jservlets
HelloWorld.java is in src folder
HelloWorld.class is in jservlets folder
HelloWorldExample.xml
<Context path="/HelloWorldExample" docBase="HelloWorldExample" debug="0"
reloadable="true" crossContext="true">
</Context>**************************
hello.jsp
<HTML>
<HEAD>
<TITLE>Hello</TITLE>
</HEAD>
<BODY>
<FONT SIZE="4">
<P>
Please enter your name:
<FORM
METHOD="Post"
ACTION="servlet/jservlets.HelloWorld">
<TABLE BORDER="3" CELLPADDING="1" WIDTH="100%" ALIGN="CENTER">
<TR>
<TD><B>Name:</B></TD>
<TD><INPUT TYPE="text" NAME="Name" VALUE="" SIZE="65"> </TD>
</TR>
</TABLE>
<P>
<INPUT TYPE="SUBMIT" VALUE="Submit">
</FORM>
</FONT>
</BODY>
</HTML>******************
HelloWorld.java
package jservlets;
import java.io.*;
import java.util.Date;
import java.util.*;
import java.text.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class HelloWorld extends HttpServlet
PrintWriter out;
PrintWriter err;
String strName;
public void displayMessage(HttpServletRequest request, HttpServletResponse response)
throws Exception
try
if (!strName.equals("") && strName != null)
out.println("Hello " + strName + "" + "<P>");
out.println("Hello World" + "<P>");
else
out.println("Hello World" + "<P>");
catch (Exception e)
out.println("Exception: Could not display message." + "<P>");
err.println (e.getMessage () ) ;
out.println("<P>");
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
try
response.setContentType("text/html");
out = response.getWriter();
err = response.getWriter();
strName = request.getParameter("Name").trim();
out.println("<html><head><title>");
out.println("</title></head><body>");
out.println("<FORM");
out.println("METHOD=POST");
out.println("ACTION=http://localhost:8080/HelloWorldExample/hello.jsp>");
out.println("<TABLE ALIGN='RIGHT'>");
out.println("<TR>");
out.println("<TD>");
out.println("<INPUT TYPE=\"SUBMIT\" VALUE=\"Hello World Page\";>");
out.println("</INPUT>");
out.println("</TD>");
out.println("</TR>");
out.println("</TABLE>");
out.println("</FORM>");
out.println("<BR CLEAR='all'>");
out.println("<P>");
displayMessage(request, response);
out.close();
out.println("</body></html>");
catch(Throwable e)
e.printStackTrace();
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
doPost(request, response);
web.xml
<servlet>
<servlet-name>HelloWorld</servlet-name>
<servlet-class>jservlets.HelloWorld</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HelloWorld</servlet-name>
<url-pattern>/servlet/HelloWorld</url-pattern>
</servlet-mapping> ******************************
HelloWorld.java can be compiled by using javac.
Once compiled, HelloWorld.class would be moved to the jservlets folder.
FYI, coding the above url-pattern results in:
HTTP Status 404
The requested resource (/HelloWorldExample/servlet/jservlets.HelloWorld) is not available
The following url-pattern in the web.xml file permits the servlet to be executed but results in a null pointer exception:
<servlet-mapping>
<servlet-name>HelloWorld</servlet-name>
<url-pattern>/ </url-pattern>
</servlet-mapping> **************************************************
RobinThis problem was resolved.
In hello.jsp
ACTION="servlet/jservlets.HelloWorld">
was replaced with
ACTION="servlet/HelloWorld">
Robin -
Start java app from a jsp or a servlet?
HI ,
I want to know if it possible to start a java application using Runtime and exec(command).
I mean launch abc.java from abcservlet or from abclaunch.jsp (with a button click) any exmaples ?
thanks,
-G.I want to know if it possible to start a java
a application using Runtime and exec(command).
I mean launch abc.java from abcservlet or from
m abclaunch.jsp (with a button click) any exmaples ?If a servlet class calls runtime.exec, it'll run a program on the server.
Use webstart or an applet if you want some action to happen at the clients side. Servlets only hand HTML to the client, no Java context. -
How to invoke DOS application from Java application??
I try the following but it didn't work to invoke command prompt and java.exe, it
is working to invoke javac.exe. Any ideas why??
import java.io.*;
public class CallJavaTest
{ public static void main(String[] args)
{ try
Runtime.getRuntime().exec("C:\\WINNT\\System32\\cmd.exe"); //doesn't work!!
Runtime.getRuntime().exec("javac "+ "Test.java"); //it works!!
Runtime.getRuntime().exec("java "+ "Test"); //doesn't work!!
catch(IOException e)
System.out.println(e);hi
String[] cmd = {"cmd","/c", "start",enteryourdoscommandhere};
Runtime rt = Runtime.getRuntime();
Process ps = rt.exec(cmd);
ps.waitFor();
int ev = ps.exitValue();
it works for my winXP.
hope it can helps and not too late .. -
Invoking java exe from C++ code
Most of my applications are in c++, i have one application in java.
How can I invoke the java application(jar) from c++ code?Hi We can do this by using EXTERN C functionality provided by c++ ,
by using this we can call the Java functions from Java .class file.
or .jar file.
(for java developers ......its similer to JNI)
if you want more details aboth such code just search it on web , you will get number of programs here.
Thanks,
-Akshay -
Invoking Java Applet from SAP Netweaver Eportal using java webdynpro
Hi ,
We are using SAP Netweaver portal version 7.0.WE want to invoke java applet into webdynpro java application on button click.
The Applet should open in a new window when the particular parameter is selected and the button is clicked
The code is given below:
String html = "<HTML> <HEAD></HEAD> <BODY><APPLET code=\"org.faceless.pdf2.viewer2.PDFViewerApplet\" type=\"application/x-java-applet;version=1.4.2_05\" archive=\"bfopdf.jar\" width=800 height=600></APPLET></BODY></HTML>";
IWDCachedWebResource resource = WDWebResource.getWebResource(html.getBytes("UTF-8"), WDWebResourceType.HTML);
resource.setResourceName("HTML_inline.html");
IWDWindow window = wdComponentAPI.getWindowManager().createNonModalExternalWindow(resource.getAbsoluteURL(),"Image");
window.removeWindowFeature(WDWindowFeature.TOOL_BAR);
window.removeWindowFeature(WDWindowFeature.ADDRESS_BAR);
window.removeWindowFeature(WDWindowFeature.STATUS_BAR);
window.open();
But after clicking on button new html window is opening and the applet is not showing properly. The java console showing the error:
java.lang.ClassFormatError: Truncated class file
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(Unknown Source)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Unknown Source)
at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Exception: java.lang.ClassFormatError: Truncated class file
Please suggest how to solve this error.
Regards,
DhrubaHi,
I'm not sure, but I believe the 'code' argument should end with '.class'. However, your implementation of displaying a Java applet seems ok, the error is within the applet's Jar file
Anyway, have a look at http://download.oracle.com/javase/1,5.0/docs/guide/plugin/developer_guide/using_tags.html#applet and http://www.w3.org/TR/html401/struct/objects.html#h-13.4 on how to use the <applet> tag
As a test, you could try and create a local HTML document on your local desktop, including the applet. I would suspect you will receive the same error in your Java console
I believe the only option is to recompile your Java applet (if possible at all) against a newer JDK (1.4 and up) -
Running Java applications from within JSP
Hi Folks,
First of all, apologies if this post is either 1) in the wrong forum or 2) a horrendous mis-application of java/JSP :D
I have a java test harness application that I have created, it runs from the command line, taking two arguments (the name of the app you want to test and the location of the properties file) and it then looks up the app in the properties file and tests the application - writing results to html reports and errors to logs... all pretty standard so far.
The apps i normally test are usually on an app server (normally IBMs WAS), so I thought, why dont I create a Web Application with a nice JSP page listing all the applications that can be tested(extracted from the properties file) and allow the user to go to the jsp and just click the "test this service" button or "view results" button for any service - just to make it more manageable.
So I have created the JSP page with the list of applications, and the links to all the result.html files - so now I just need to implement the functionality to be able to hit the link "Test now" and the test harness runs in the background.
Does anyone please have any ideas?
The best i came up with was creating a link to a new jsp page that had the code on it to create the main Test Harness object and then calling the execute() method - however, when i press the link i get taken to the page but my tests arent run? (this test was run on Tomcat if that makes any difference)
Any ideas? of any better ways to approach the task?
Thanks in advance guys!!Start with Java EE tutorial part II: [http://java.sun.com/javaee/5/docs/tutorial/doc/bnadp.html].
To create a Servlet you basically just extend HttpServlet and implement the appropriate methods, such as doGet() for GET requests and doPost() for POST requests. To run it, you need to define it in the web.xml and map it on an appropriate url-pattern with which you want to invoke the servlet by URL.
To fullfill your requirement, I think implementing doGet() ought to be sufficient. E.g.
yourpackage.YourServlet.javaprotected void doGet(HttpServletRequest request, HttpServletResponse response) {
YourJavaClass yourJavaClass = new YourJavaClass();
Object someResult = yourJavaClass.doSomething();
request.setAttribute("someResult", someResult);
request.getRequestDispatcher("yourPage.jsp").forward(request, response);
}yourPage.jsp<p>Result: ${someResult}</p>web.xml<servlet>
<servlet-name>yourServlet</servlet-name>
<servlet-class>yourpackage.YourServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>yourServlet</servlet-name>
<url-pattern>/yourServlet</url-pattern>
</servlet-mapping>Invoke it by [http://localhost:8080/yourContext/yourServlet].
Maybe you are looking for
-
I recently sold my iphone 4s back to att and they whiped it clean and now i have a galaxy s5 and my brother still has the iphone but when he sends me texts they dont always go through and i need help on what to do next
-
Setting up my new pro8600inkjetprinter
Hi, can I go wireless with my printer if I don't have a dsl. modem or a enternet modem? I am using a jet pack for my internet connection at home and it gives me a connection for my Tablet and my laptop. The jet pack is Verizon's answer to getting an
-
5310 Problems automatically restart???
I just bought the Nokia 5310 only 2 month, but there are a lot of problem I was found. First, the phone automatically restart itself. Second, the phone usually show "Please check your Info service". How can I solve the problems?? and could you tell m
-
URGENT! Share session object in JSP and JServlet
Dear all, I am new to OAS. I am now trying OAS by build a simple Shopping Cart application. Currently, I use JSP to build user interface and Servlet to build bussiness logic. So I use JSP cartage and JServlet cartage to build the application. However
-
Change my Apple ID e-mail address to my new iCloud e-mail?
I've had an Apple ID account for many many years and it was a "hotmail" account. I recently created a new iCloud e-mail address (@me.com) address and tried to change the current (hotmail) address to the new (@me.com) address but an error message come