Java inside javascript
Hi
i am getting alert messages to be displayed in the GUI from the properties file.
can anyone tell me how can i use java inside javascript..?
so that i can use ResourceBundle file in javascript.
Regards
Sonia
Do you know how to retrieve the text you want from the properties file? If so then all you have to do is add:
<script type="text/javascript">
alert('<%=variablename%>');
</script>
to your page, where you replace variablename with the name of the String you want alerted.
If you don't know how to retrieve what you need from the properties file, maybe you should ask that question.
Similar Messages
-
Regarding use of java code inside javascript
Hi ,
I have doubt regarding how to use java code inside javascript,
i am giving my application code here
<%@page import="java.util.*"%>
<%@ page import="com.suuny.sard.pmt.pat.*"%>
<SCRIPT LANGUAGE="JavaScript">
function fun(){
var ac=document.login.Projectname.options[document.login.Projectname.selectedIndex].value;
var c = document.login.task1.value;
alert(ac);
alert(c);
return true;
</SCRIPT>
<form name="login" action="/pmt/jsp/Leavemanagement/Leave_Ems_HomePage.jsp" method="get" encType="x-www-form-encoded" >
<table width="100%" Align="Center" cellspacing="0" cellpadding="0" border="0">
<tr class="tablerow"><td colspan="6" align="center"><font class="pagehead" align="center">Create Tasks</font></td></tr>
<tr class="tableheader">
<th>Project
<th>Task-Id
<th>TaskName
<th>Assigned To
<th>description
<th>Milestone
</tr>
<%
for(int i=1;i<2;i++){%>
<tr class="tablerow"><td align="center">
<select class="SELECT" NAME="Projectname" VALUE=" " onchange="return fun();" >
<!--<option value=""> </option>-->
<%
ArrayList ar =null;
ArrayList projectids=null;
Hashtable ht = new Hashtable();
ProjectNames pnames=new ProjectNames();
ht = pnames.getProjectNames();
ar=(ArrayList)ht.get("projects");
projectids=(ArrayList)ht.get("projectIds");
for(int j=0;j<ar.size();j++){
out.println("<option value=\""+projectids.get(j)+"\">"+ar.get(j)+"</option>");
%>
</select>
<%
out.println("<td align=\"center\"><input type=\"text\" name=\"task"+i+"\"value=\"\" size=\"25\"></td>");
out.println("<td align=\"center\"><input type=\"text\" name=\"taskname"+i+"\"value=\"\" size=\"25\"></td>");
%>
<td align="center">
<select class="SELECT" NAME="Projectname1" VALUE=" ">
<!--<option value=""> </option>-->
<%
ArrayList ar1 =null;
ar1 = pnames.getProjectResource("VXML02");
for(int j=0;j<ar1.size();j++){
out.println("<option value=\""+ar1.get(j)+"\">"+ar1.get(j)+"</option>");
%>
</select>
<%
out.println("<td align=\"center\"><input type=\"text\" name=\"description"+i+"\"value=\"\" size=\"25\"></td>");
out.println("<td align=\"center\"><input type=\"text\" name=\"milestone"+i+"\"value=\"\" size=\"25\"></td><tr>");
out.println("<tr class=\"tablerow\"><td colspan=\"6\" align=\"center\"><input class=\"txtbuttonsmall\" type=\"submit\" value=\"save\"></td>");
%>
</Table>
</form>
My question is :
I selected one project from first combo box ,i need project members corresponding to the project.
In my code "pnames.getProjectResource("VXML02");" in this function iam passing one static projrct value,but i need dynamically selected project from first combo box(<select class="SELECT" NAME="Projectname" VALUE=" " onchange="return fun();" >),so please help me guys.Hi Marco,
I "executed" some java code within XSLs file. I have quoted the word executed because I didn't really run java code, but I used a simply trick that I describe you below.
Into your XSLs put an iframe which is hided (it has an height of 0 pixel). As src of the iframe put the address of a portal component which execute your code (in my case calculate some PCD URL of some pages into a defined role). As result of component execution, I use the response.write method in order to execute some jscript code, which is able to interact with the HTML generated by XSLs files, for example in my case response.write put the PCD URL into a drop down list placed into the "edit" form.
This works fine. I don't know if is suitable also for your case, anyway could be a hint, but pay attention to Roland's recommendations.
Ciao
Roberto -
Can we able to run java program inside javascript
Hi all
can we able to run java program inside javascript or integrate java with javascript.....whether its possible...No. You can't execute Java code from within a JS script in Acrobat/Reader.
-
Java to javascript problems with '
I have a class that pass some strings to a javascript alert(<....>)
In this sting I have some < ' > and when I launch the class I get always an alert with the ASCII code of < ' >.
I used this syntax inside the String
String alertSctring="Let \' go";
but I get
Let ' go
Why?I'm sure the problem has to do with escaping values in strings in Java and Javascript.
Try using double-backslash quote.. like "Let \\' Go" -
hello ppl,
i want to know if its possible to execute JSP code inside javascript..hi damion,
thanks for being so nice.. and wat i want to do is pretty simple.. i have a jsp page with a text field and a button in it. wat i want is, everytime the button is clicked, data from a field in the database should be displayed sequentially, i.e something similar to generating the next sequential rollno when we click 'next'. Also the sql query to be submitted is also generated dynamically in the JSP page. how can i go about doing database operations using javascript? or is there any other simpler way of doin it? hav i made myself clear?
ll send u the code which i've employed..
this is the jsp page:
<HTML>
<HEAD>
<TITLE>
Welcome to fstaff1.jsp
</TITLE>
<jsp:useBean scope = "page" id = "rollnogenerator1" class = "coreservlets.rollnogenerator" />
<script>
function generate(){
fstaff1.regno.value = <%=rollnogenerator1.getRollNo()%>;
}</script>
</HEAD>
<BODY>
<%
rollnogenerator1.setQuery("select * from marks");
rollnogenerator1.connect();
%>
<form name = 'fstaff1' method = 'post'>
<input type='text' name = 'regno' value = <%=rollnogenerator1.getRollNo()%>>
<input type='button' name = 'next' value='next' onclick='genrerate()'>
</form>
</BODY>
</HTML>
and here is the bean i used:
package coreservlets;
import java.io.*;
import java.util.*;
import java.sql.*;
public class rollnogenerator {
public rollnogenerator() {
private String query = "not set yet";
ResultSet rs;
private String rollno;
public void connect(){
try{
Class.forName("org.postgresql.Driver");
Connection connection = DriverManager.getConnection("jdbc:postgresql://localhost/pulls","postgres","this");
Statement st = connection.createStatement();
rs = st.executeQuery(query);
rs.next();
catch(Exception e){}
public String getRollNo(){
try{
rollno = rs.getString(4);
rs.next();
catch(Exception e){}
return(rollno);
public void setQuery(String msg){
this.query = msg;
public static void main(String[] args) {
can u help? -
Java vs Javascript NOT THE SAME THING
Since we're all just users here it might be appropriate to remind people that Java and Javascript are two distinctly different things. With the recent warnings about Java some might be inclined to also disable Javascript in their browsers. There is no need to do that.
Even thought the two frameworks have similar names they are not related.drcouzelis wrote:
grabbexi wrote:I want to understand Unix/Linux better
Which aspect of Unix / Linux do you want to understand better?
Options include:
Networking
Servers
System administration (user accounts, permissions)
Software development
Package management
Differences between distributions / operating systems
Kernel compiling
The Linux Standard Base (LSB)
Shared libraries
Version control software
Embedded linux
The init process, boot manager, and dual booting
File systems
And other stuff.
I was thinking a basic mix of everthing above, basically. Like: What are libraries? How does the system administration work? How does the kernel work? Etc. I mean - the answers are often not so complicated to understand on a basic level. My problem is, I don't know what questions to ask.
I think I'm looking for some "tasks" which don't require a lot of time, I don't really HAVE the need to do extremely much on my Arch - but I would love to be ABLE to do more.
bohoomil wrote:Well, I believe you mean 'using a particular Linux distribution' in the first place.
Yes, you are right - that is what I meant.
General response: Thanks to all of you so far. I'm starting to understand what I should do, just hoping I'm on the right track now. -
Hi ,
I need help . I need to communicate from applet to java script in the same page . the only thing i came across is netscape.javascript.JSObject which gives access to DOM object . but this thing does not work with MAc system . i am using power MAc with classic JVM MRJ 2.2.5 . If some body can help me on this
SiddhuI dont know whether you can do the reverse communication from java to javascript or not put once method define as public can be aacessed by javascript method and define the class as public.
-
Error using java and javascript
I have a jsp page that links to a bean and is working fine (getting data from the database).
On a html form I have a button with a picture that fires off javascript when clicked:
<BUTTON TYPE=reset onclick=showinfo('<%=index%>')>
<IMG SRC="http://localhost:8080/Portal/Images/q2.bmp" ALT="Info">
</BUTTON>
The javascript function just opens a new window and displays the text sent in:
<Script Language=JavaScript>
function showinfo(arrayindex)
InfoWin=window.open("","InfoWin","width=345,height=220");
InfoWin.document.write(arrayindex);
return false;
</Script>
Well in the above example index is a number (pulled from the database using a java bean and javascript converts it into a string then the function displays it correctly. If I replace <%=index%> with regular text it works fine as well(because java isn't used to pull data)! The problem occurs when I retrieve text data from the database and send it to the function. The web page gives errors about a nonterminating string. But I can move the code to somewhere else on the form(as long as I don't send it to java script) and it will print the text to the screen. I can also view the source of the web page and the html shows the text from the data base as if I hard coded the text into the javascript!!!!!!!!!!!!!!!!!
This must be a bug between java and javascript!
-can pass numbers(from a database) between the two
-can't pass text (from a database)between the two
Any info would help!Found the problem myself!
I am using an odbc connection to msaccess and the spaces in the text was messing things up!
After taking out the spaces it worked again. -
What's the difference between java and Javascript?
I a new programer, I am getting Java down. Now I want to add some java scripts to my site. Is there any difference between java and Javascript? Can I use the Java API site refference and classes? Thanks..
Java is a programming language, Javascript is more for web pages. It is used to add interactivity to your web pages. 2 different languages.
check out www.java.sun.com for Sun Java stuff.
Lynn -
Wanting to send SMS text from a mobile phone to a webpage, the wepage has a scrollbar that will change everytime an SMS text message is sent. Is this going to be Java or Javascript to allow this to work ?.
Cheers.Wanting to send SMS text from a mobile phone to a
webpage, the wepage has a scrollbar that will change
everytime an SMS text message is sent. Is this going
to be Java or Javascript to allow this to work ?.
Cheers.It would be a wap page for the mobile phone. You could use a jsp for that. A controller would get the info from the jsp and send it to some code using Noctor API(www.noctor.com) or something similar. Using this API you would opene an SMPP connection to an SMSc and send the message to it.
I would suggets you try to understand the SMPP API a little bit and gothrougn one of the APIs which supports the protocol. -
Hi
i create a cookie called "SaveState" from javascript in my JSP dynpage.
I want to read this from java (NOT JAVASCRIPT).
Is this possible?
if not, is there some kind of portal memory I can use to pass values between java and javascript?
thanks
Anton KruseHi,
<b>Domain</b>
The "domain" parameter is used to set the domain the cookie is accessable to. A path can be set for your own domain only and the domain path must include at least two periods (.domain.com). It must match your server's domain name. Therefore cookies are not a security risk since only the server that sets them can use them.
Check this to know more about cookies:
http://www.comptechdoc.org/independent/web/cgi/javamanual/javacookie.html
If you still have questions, I will suggest to google on cookies.
Greetings,
Praveen Gudapati -
Use plsql within java (or javascript) programs
hi,
to interface with oracle db, I've always used PLSQL blocks within programs written in C language but now I've to insert PLSQL blocks in java or javascript language
I don't know if it's possibile and I don't know how to do it
may someone explicate it to me?
thanks a lot!mfran2002 wrote:
hi,
to interface with oracle db, I've always used PLSQL blocks within programs written in C language but now I've to insert PLSQL blocks in java or javascript language
I don't know if it's possibile and I don't know how to do it
may someone explicate it to me?
thanks a lot!There is no pre-processor in the Java standard packages (don't know if there is one out there somewhere, but I imagine that there probably is) as there is for Pro*C. Oracle have one in store??? ... hope so.
So in Java the SQL (including function calls) is built as Strings, which are then fed as arguments to the execute methods of Statement, or to the PreparedStatement itself - that tutorial will spell this all out well.
So the SQLs can be static or build dynamically.
~Bill
Also ... you can store Java stored procedures in the Oracle DB, wrapped as PL/SQL functions and then call them as such. -
What can Java inside cell phone do?
hello,
i would like to know what can Java inside my cell phone do? can it:
1) run in a background
2) initiate a phone call
3) send an sms or receive an sms
4) can it control bluetooth and to what extend
what are things that java cannot do?
thank you very much!Hi,
J2ME apps run in sandbox mode. Things can be done using various APIs. To
answer your specific questions:
1) depends on the host device implementation, this is not defined by JCP
2) AFAIK not (due to security). There might be an API however that allows you to
do this on certain devices.
3) Yeah, no problem. See http://java.sun.com/products/wma/
4) Depends on APIs provided by device manufacturer. JCP defined http://www.jcp.org/en/jsr/detail?id=82.
The things J2ME can not do are mostly features like accessing your phone
book, use built-in camera (unless APIs are provided), floating point math
operations, ...
Reading J2ME related JSRs from http://www.jcp.org/ will give you the overview
of what's defined and can be expected from all compliant phones. Other
features may or may not be implemented.
Hope this helps,
Peter -
I have a peculiar problem. ..
i need to call a javascript function from jsp and get the string value returned by the function...
i am calling the function like this
<BODY BGCOLOR="#FDF5E6" onload="respPrompt('<%=line%>')"> in jsp file
here is the function..
script language="JavaScript">
function respPrompt(line) {
alert("hello")
var favorite = prompt('Edit the line?',line);
if (favorite) alert("edited line is s: " + favorite);
else alert("You pressed Cancel or no value was entered!");
return favorite;
</script>
i need to get hold of the value "favorite" in the jsp programm...and need to write it to a file...am doing this since i cannot handle files from inside a javascript function....
plz gimme ur suggestions..
thanks
raoJava runs on the server
javascript runs on the client in the web-browser.
The only communication between the two is via http.
You send a request (with request parameters)
You receive a response in the form of an HTML page.
Thats all the communication there is.
Java can't call javascript, and javascript can't call java.
If you need to prompt the user for info, send back an html page asking for that info, and then have them submit that result back to another servlet/jsp
Cheers,
evnafets -
Question about struts inside javascript variable
Hi, actually i'm using a struts + javascript to create HTML code that i use inside a popup window...
My (working) code is:
idoc="";
/* var cols = parent.document.getElementById('rowA').getElementsByTagName('THEAD')[0].getElementsByTagName('TH'); */
var idoc='<html:form styleId="InsertNewItem" action="/nw/insertnewitem.do?target='+parent.newPop.action+'">';
idoc+='<TABLE><TBODY>';
var hiddenForm = getParentObj('hidden_data_form');
var cols = hiddenForm.getElementsByTagName('INPUT');
var test;
test="cippa";
for(k = 0; k < cols.length; k++) {
if(cols[k].id.substring(0,3) == "hh_")
idoc += "<TR><TD>";
idoc += cols[k].id.substring(3);
idoc += "</TD><TD>";
idoc += '<html:text property="'+cols[k].id+'" value=""/>';
idoc += "</TD></TR>";
idoc+='</TBODY></TABLE>';
idoc+='</html:form>';
var towr = document.getElementById("subwin_body");
towr.innerHTML = idoc;
The problem is when i try to add a <html:select> to the code, more precisely i added just before the end of the table these lines:
idoc += "<TR><TD>Ditta:";
idoc += "</TD><TD>";
idoc += '<html:select property="ditta_id">';
idoc += '<html:options collection="sel_ditta_list" labelProperty="label" property="value"/>';
idoc += '</html:select>';
idoc += "</TD></TR>";
... but i cannot get it to work because struts seems to make some mistake with quotes and in javascript console window i get this error:
Error: unterminated string literal
File source: http://localhost:8180/nw/jsp/insertNewItemOperatore.jsp
Row: 121, Column: 10
Source Code:
idoc += '<option value="1">1</option>
(note the missing ending single-quote)
I can't understand why because with <html:text> field the same "trick" works fine... any ideas?
Thanks in advance
Luca
Message was edited by:
spallaredcan you post all of your source code for the .jsp and then try running the page and once it fails do a View Source and then paste in all the generated code so that we can look at that as well.
i'm not totally positive but i have a pretty good feeling what is going wrong. the struts optionsCollection tag will render a bunch of <option> elements but print a newline after each one, which means you probably end up with something like
var whatever = '<option ...>.........<option>
<option ...>.........<option>
<option ...>.........<option>
<option ...>.........<option>';
correct? if so, that is not valid javascript.
Message was edited by:
den2681
Maybe you are looking for
-
I HAVE SPENT THE LAST SEVERAL WEEKS FIGHTING WITH ADOBE OVER THIS PROBLEM; THEIR SOLUTION WAS TO CHANGE TO IE, I HATE IE, BUT TRIED IT WAS A TOTAL FAILURE, IT ALSO CREATED A WHOLE NEW SET OF PROBLEMS WITH EVERYTHING THAT IE WANTED TO PUT ON MY HOMEPA
-
Want to import/transfer ratings of songs, etc. Can't figure out how.
I changed computers to use the new one as my primary source for iTunes use. Music and everything else imported / transferred, BUT the rating for each song, etc., DID NOT transfer. Is this possible or do I have to re-rate all songs??? How can I transf
-
Installing Oracle Client 81 on XP
Hi, I am attempting to install Oracle 8i client on Windows XP Professional and the the setup dies immediately without any error messages. The installation notes do not list XP as one of the Windows supported OS. Is it possible to install 8i client on
-
PSE 8 for Mac - Program Error - how can I save?
I'm using PSE8 for Mac on an Intel MacBook with 4Gb or RAM, running Snow Leopard 10.6.2. When I'm editing JPEGs, usually all goes well; but sometimes I find I can't save a file I've edited, and I get a dialog box saying: "Could not complete your requ
-
Can't connect to Airport Express since upgrading my router.
I recently changed my router from an old Netgear 834 to a TP-Link W8961ND and now I keep losing the Airplay Speaker logo from my iphone4, ipad2, and itunes on my Windows 7 PC. When I unplug the AE and restart it connects but afer abour 30-40mins it d