Jsp output as javascript
i am developing an app using google map api which uses javascript
i need a part of the javascript dynamically generated based on data in a database
is there a way to do it?
thanks but i am still confused
i have never used beans
this is the code i need to modify:
<script type="text/javascript">
function initialize() {
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("map_canvas"));
map.setCenter(new GLatLng(28.63786941260399, 77.22084045410156), 13);
var polyline = new GPolyline([new GLatLng(37.4419, -122.1419),
new GLatLng(37.4519, -122.1519)
], "#ff0000", 10);
map.addOverlay(polyline);
</script>i need to populate from the co ordinates a database
i tried the following:
<script type="text/javascript">
function initialize() {
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("map_canvas"));
map.setCenter(new GLatLng(28.63786941260399, 77.22084045410156), 13);
var polyline = new GPolyline([
<%
Connection con=null;
try
Class.forName("oracle.jdbc.driver.OracleDriver");
con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","scott","tiger");
Statement stmt=con.createStatement();
ResultSet result=stmt.executeQuery("SELECT SNAME,LAT,LON FROM COORDS ");
while(result.next())
out.println("new GLatLng("result.getString(2)","result.getString(3)");
catch(Exception e)
out.println("Exception:"+e);
if (con != null) {
try {
con.close();
} catch (Exception ignored) {
; // ignore
%>
//new GLatLng(37.4419, -122.1419),
//new GLatLng(37.4519, -122.1519)
], "#ff0000", 10);
map.addOverlay(polyline);
{code}
Edited by: greenhorn on Dec 3, 2008 9:09 PM
Similar Messages
-
How to pass a jsp variable into javascript??
<p><%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<p><%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<p><html>
<p><c:set var="binrmapi" value="http://localhost/paas-api/bingorooms.action;jsessionid=XXXXXX?userId=TEST2&sessionId=1&key=1" />
<p><c:import var="testbinrm" url="${fn:replace(binrmapi, 'XXXXXX', jsessionid)}"/>
<p><c:set var="tuples" value="${fn:split(testbinrm, '><')}" />
<p>Time until next game
<p><c:forEach var="tuple" items="${tuples}">
<p><c:if test="${fn:contains(tuple, 'row ')}">
<p> <p><code>
<p> <c:set var="values" value="${fn:split(tuple, '=\"')}" />
<p> <font color="blue">
<p> <c:out value="${values[17]}" />
<p><c:set var="remainingtime" value="${values[17]}" />
<p> </font>
<p> </code>
<p></c:if>
<p></c:forEach>
<p><form name="counter"><input type="text" size="8" name="d2"></form>
<p><script>
<p>var milisec=0
<p>var seconds=eval("document.myForm.remaining").value;
<p>function display(){
<p> if (milisec<=0){
<p> milisec=9
<p> seconds-=1
<p>}
<p>if (seconds<=-1){
<p> milisec=0
<p> seconds+=1
<p> }
<br>else
<p> milisec-=1
<p> document.counter.d2.value=seconds+"."+milisec
setTimeout("display()",100)
<p>}
<p>display()
<p></script>
<p></body>
<p></html>
<p>This is my code that i was working on, in the jsp part of the script, i get a api call and save a value of time in the variable remainingtime.. and in the javascript, i try to have a countdown clock counting down the remaining time.. but i guess it doesnt work.. how can i get that working? thanks alot
Message was edited by:
hamham3001
Message was edited by:
hamham3001
Message was edited by:
hamham3001
Message was edited by:
hamham3001Re: How to pass a jsp variable into javascript??Here is the sameple one, hope it will solves your problem.
<html>
<body>
<form name=f>
<%!
String str = "A String"
%>
<script>
var avariable = <%=str%>
<script>
</form>
</body>
</html>
Let me know if you face any problem -
How to pass an array which in the jsp to a javascript file
now i have 2 files: jsp and js(javascript)
i want pass an array which in the jsp to another file--> js file
how can i do it ???
can u give me some related links or some source codes as the references???
thxbcos ....my senior has resigned!!! so i take over his job !!!!!
depend on the talent and the project ....only that way to implement to whole project !!!!
but , i had settled it already ....
it is very simple
in the middle.jsp
Collection result = menuManager.getUserRoleMenu(webSessionUser.getGnuserId());
String menuname[]=new String[110];
int menucounter=0;
Iterator vi = result.iterator();
while(vi.hasNext())
HashMap hm=(HashMap)vi.next();
menuname[menucounter]=hm.toString();
menucounter++;
int i;
String tempstr="";
for(i=0;i<menuname.length;i++)
tempstr+=menuname[i]+",";
session.setAttribute("menuname",tempstr);
%>
<script language="javascript">
menu123("<%=tempstr %>");
</script>
in the body,js
function menu123(string123)
//doing
so ....through the script --menu123
i can get the string from jsp to the js!!!!!
is it very simple, but it spends my 2 days!!!
i just learn javascript ....about 1 month !!! -
Passing jsp variable into javascript.....
Hai friends,
Look this code.....
var mywindow= window.open( ......)
mywindow.<%= loc%>.style.visibility = "hidden";
loc is my jsp variable passing dyanamically to the script....
But it is not taking....
when i assign jsp var into javascript like
mywindow.somehardcodedvalue.style.visibility = <%= loc%>;
it is working fine ....
pl reply me.......Hi,
It is not working.My code is like....
String loc=(String)arrStr;
%>
<script language="JavaScript" type="text/JavaScript">
mywindow.<%= loc%>.style.visibility = "hidden";
</script>
<% -
I am trying to use the <jsp:output> tag within jdeveloper10.1.2, but it is not included within the tags for JSP in the component pallete, so I keep getting an error. Any idea, pls ?
jsp:output is a J2EE 1.4 JSP 2.0 tag.
JDeveloper 10.1.2 provides only the JSP 1.2 tags.
http://java.sun.com/products/jsp/syntax/1.2/syntaxref12.html
JDeveloper 10.1.3 supports J2EE 1.4 (JSP 2.0).
Some of the JSP 2.0 tags are not in the Component Palette.
jsp:output tag, jsp:invoke and jsp:text tags which are jsp 2.0 tags are not in the Component Palette.
http://java.sun.com/products/jsp/syntax/1.2/syntaxref12.html -
How to use JOptionPane in jsp, instead of javascript message alert box?
HI,
How to use JOptionPane in jsp,
instead of javascript "message alert box"?
I hate javascript,
I'd like to only use java in jsp. don't use javascript.
javascript is client side,
jsp is server side. i know that.
how to... instead of javascript box?
how to use ... message box in webpage?
don't use applet,,,, don't use javascript,,,
hm...zzzZzz
I hate javascript..T.T
<SCRIPT language=JavaScript>
alert("hate javascript");
</SCRIPT>
===>>>>
In this way,,
JOptionPane.showOptionDialog(null,"I love java")
I'd like to only use jsp and java and html...in webpage.
don't use javascript....
Why? don't sun provide message box in jsp, instead of javascrip box?
Why?
Edited by: seong-ki on Nov 4, 2007 8:38 PMDrugs are bad, m'kay?
-
Extra white spaces in JSP output
Hi,
My JSPs contain a large use of JSTL and other custom Tags.
The problem is that the output contains too many new lines and spaces.
I found out that APACHE Tomcat has a servlet parameter (trimSpaces=true) that solved this problem.
Does Weblogic (9.1) have something similar ?
Does JSPC / APPC have a special options that can solve this ?
please advise,
Avivi.Before diving into this, one thing I would ask you: Why does it matter if there are extra spaces? Did you determine that your primary users are using a slow connection? Before trying to optimize this, make sure that you really have a problem to solve. You might try saving off the currently generated HTML into a test page, and compare it to a similar one with all ignorable spaces removed. If you see no difference in performance, then don't bother doing this.
Nevertheless, one strategy for reducing empty space in JSP output is to put the ends of the JSP directives and actions on the next line, with no newlines after them.
For instance, a pair of lines like this:
<%@page import="foo.bar" %>
<%@page import="bar.foo" %>
Would be instead:
<%@page import="foo.bar"
%><%@page import="bar.foo"
%> -
How I detect in a dynamic website either PHP or CFM or JSP that cookies & javascript are enabled ?
You do that on the browser end using JavaScript. For cookies, simply establish session variables in PHP or whatever you use. if the browser refuses them, they wil lreturn a respective value in the referrers...
Mylenium -
IE don't display JSP output. It pop up download dialong and open Dreamwea
IE don't display JSP output. It pop up download dialong and open Dreamweaver.
I dont' know why, but when run in Netscape is OK
Anyone please help.Looks like your problem lies by the file associations, i.e. extension of your jsp file (.JSP) is associated in your operating system with DreamWeaver rather than with IE. If you are using Windows you should be able to change file associations, so that all web pages including JSP will be opened in your browser.
-
Can I use a jsp variable in javascript? If so, how? It would be used in an "if" statement:
function get This() {
if (document.form.tfName.checked==true) || (<%jsp>) {
then do this...}
}My problem is I am grabbing a persistant value from a
value object: the value of a checkbox as
<%=InformationVO.isChecked()%>If (==true) i want javascript to enable a button on
load. If not disable it. Plus I hav javascript on
the page that controls this while the page is open.
Just don't know how to incorporate the two scenarios
s for:
1.checking the value to ernable/disable the sumbit on
load with the value of the VO
2. using javascript to control the enable/disable
while page is laodedYou want something like this?
<%
boolean enableButton = InformationVO.isChecked();
%>
<html>
<head>
<script language="javascript">
// load event, enables or displables button depending on the InformationVO.isChecked value.
function doMyLoadEvent(){
if(<%=enableButton%>){
// enable mySubmitButton object
}else{
// disable mySubmitButton object
// submits the form
function submitForm(){
var frm = document.forms[0];
frm.action = "path to your servlet goes here";
frm.submit();
</script>
</head>
<body onload="javascript:doMyLoadEvent()">
Woopdy doo!
<form method="post" action="" name="">
<input type="button" name="mySubmitButton" value="Submit" onclick="javascript:submitForm()">
</form>
</body>
</html> -
Calling jsp file from javascript function
How can i call a jsp file itself from javascript function written in it?
I do not think you can invoke the current jsp directly using javascript.
If the effect you are trying to achieve is to reload the page, then you could execute the servlet / code which called the current jsp. -
Hi,
I have downloaded the masthead portal archive and imported it into my NDS. I have added a couple of extra jsps and a javascript file. What I'm trying to do is have a popup window launch from my first jsp to hold my 2nd jsp via javascript. e.g.
The javascript calls: window.open("FFDialog.jsp","Dialog","width:200px;height:100px;toolbar:no;directories:no;status:no;menubar:no;scrollbars:no;resizable:no;modal:yes");
The popup opens, but doesn't contain my jsp (which is really just a basic html/js file).
I think its because my jsp sits under dist->PORTAL-INF->jsp and the javascript under dist->scripts hence FFDialog.jsp isn't in the same location. What needs to be the path in my window.open?
Cheers!Hi Jo,
In your jsp ,from where you are calling javascript function to call other jsp, write below code
to get the app path.
<%String webpath = componentRequest.getWebResourcePath()+"/"; %>
Now the variable have the root path for your application , So suppose your 2nd jsp page is
inside a director called jsp so now you use:-
window.open("<%=webpath%>jsp/FFDialog.jsp", "Dialog","width:200px;height:100px;
toolbar:no;directories:no;status:no;menubar:no;scrollbars:no;resizable:no;modal:yes");
Same way if you have your css file inside a directory called css use below code:-
<LINK href="<%=webpath%>css/style1.css" type=text/css rel=stylesheet>
Regards,
Piyush -
Call jsp function in javascript without using Applet
anyone knows how to call jsp function in javascript .
just as follows:
<%!
public string jspcall()
return new String("just a example");
%>
<script language="javascript">
<!--
temp = jspcall();
//->
</script>
it's desn't work.
any suggestion will help!it's was not able to call a jsp function in javascript.
jsp function was on server site while javascript normally on the client site. -
I need to be able to save what a user sees on his browser, to a local file (where the web app runs).
The content is dynamic. It is being created using a JSP.
One way to write it to a local file would be to move the content creation from a JSP to a servlet and write to the HTTP response as well as to a file in the servlet.
That's going to make it look messy.
Any thoughts on how I could make this happen while continuing to use a JSP?OK, so now I've tried it, it's essentially what is described in the J2EE tutorial:
/* File 1 */
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
* passes on a subclass of HttpServletResponseWrapper
* in order to replace the output writer.
public class OutReplacementFilter implements Filter {
public void init(FilterConfig filterConfig) throws ServletException { }
public void destroy() { }
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
//wrap the original response
HttpServletResponse newResponse = new ReplacementHttpServletResponse((HttpServletResponse) response);
//pass it to the resource
chain.doFilter(request, newResponse);
//get what the resource wrote
String output = newResponse.toString();
//put it to the output stream
PrintWriter out = response.getWriter();
out.write(output);
out.close();
//and then put it where ever else you like
System.out.println(output);
/* File 2 */
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
* returns specialized writer to capture jsp output
public class ReplacementHttpServletResponse extends HttpServletResponseWrapper {
private CharArrayWriter replacementWriter;
public ReplacementHttpServletResponse (HttpServletResponse response) {
super(response);
replacementWriter = new CharArrayWriter();
public PrintWriter getWriter() throws IOException {
return new PrintWriter(replacementWriter);
public String toString() {
return replacementWriter.toString();
}This way is easy and few keystrokes, but buffers all the output until the filter chain returns. -
How jsp to use javascript's variable??
Hi, how jsp to use javascript's variable or a jsp's variable can be assigned a value in the javascript??
thxwell i havent accessed the value of javascript variable in jsp
yet but i have accessed the value of a java variable in java script
try it
<script ...>
function jspToJavaScript(a){
alert(a);
</script>
<%
int a=10;
%>
<img src="..." onClick="jspToJavaScript(<%=a%>)">
Maybe you are looking for
-
How to tell if my wifi is working and my phones not using data when Im connected to wifi
My data is sky high and I have a feeling my wifi isn't worKing... How do I tell if when I'm connected to wifi that it isn't sucking up all my data ?
-
RoboHelp Office X5.0.1 and Office 2007
Can I use RoboHelp Office X5.0.1 with Office 2007? Thanks & best regards Andreas
-
Split audio video tracks on iMovie on iPad 3
This has probably been asked before but I'm having trouble navigating through this new support interface to find the answers. I have a new iPad 3 with Retina display. When I bought it I downloaded the latest version of iMovie for this iPad. When I dr
-
Using iTunes 7 for Windows...and my computer crashes...
I downloaded iTunes 7 for PC, using Windows, and I have two issues, one minor and one major: 1) I can leave iTunes open and running on my computer, but when I start playing songs, after a few minutes my computer crashes to a blue screen...any help? 2
-
Filtering View Data Based on Location Value
Hi, I have a mangers view in my list. we have some cluster values like this: AP/AU/MK BD/CO/EN/MV BE/CR/LH BO/KM/KG BP/BU/GR/WC DM/KT/WM I wrote CAML query for fetching data based on filter condition(i.e. Cluster value) <Query> <Where> <Eq> <