Jsp inside javascript

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?

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

  • Set jsp from javascript

    I have three "div" tags in index.jsp ,
    <div id='header'></div>
    <div id='body'></div>
    <div id='footer'></div>
    Now when window is loaded i want other jsp page to be set in the "body" div tag of index.jsp from javascript
    My javascript code
    function invokeJSP(){
    document.getElementById('body').innerHTML="<jsp:include page='test.jsp'>'";
    when I am including this code in <head > part of index.jsp its working the problem is if at all
    In test.jsp
    if i try to include this line
    <% = request.getParameter("name")%>
    its giving an error like "unterminated literal string" in javascript console
    Can anyone help me how to set the jsp from javascript
    Sorry for my bad english.This is the first time I am posting the forum
    thanks
    hema

    hi
    Thanks for the response
    but i have closed the tag in my program. Have u ever tried to invoke jsp from javascript in this way if it works plz help me.
    thanks hema

  • Want to add a jsp inside pager tag library

    Hi,
    I want to add pagination in my web center application, for This I am using pager tag lib
    But I am not able to add jsp page inside *<pg:index >* tag
    I tried it with different ways: e.g.
    A. <jsp:include page="/WEB-INF/jsp/altavista.jsp" flush="true"/>
    b> <f:subview id="subview1">
    <jsp:include page="inc.jsp" />
    </f:subview>
    When I add JSP  inside <pg:index > tag and run my jsp i am getting noting in my UI and also not seeing any error in console.
    <?xml version='1.0' encoding='UTF-8'?>
    <jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:af="http://xmlns.oracle.com/adf/faces/rich"
    xmlns:pe="http://xmlns.oracle.com/adf/pageeditor"
    xmlns:c="http://java.sun.com/jsp/jstl/core"
    xmlns:tr="http://myfaces.apache.org/trinidad"
    xmlns:pg="http://jsptags.com/tags/navigation/pager"
    xmlns:trh="http://myfaces.apache.org/trinidad/html"
    xmlns:cust="http://xmlns.oracle.com/adf/faces/customizable">
    <jsp:directive.page contentType="text/html;charset=UTF-8"/>
    <f:view>
    <af:document id="d1">
    <af:form id="f1">
    <af:pageTemplate viewId="/oracle/webcenter/portalapp/pagetemplates/nowTemplate.jspx"
    id="pt1">
    <f:facet name="content">
    <af:group id="g1">
    <af:panelGroupLayout id="pgl1">
    <div class="line topMargin20">
    <div class="unit size1of4">
    <div class="mod mod-sectionTitle">
    <span>Search Results</span>
    </div>
    </div>
    <!-- /unit -->
    <div class="unit size3of4 lastUnit"></div>
    <!-- /unit -->
    </div>
    <!-- /line -->
    <div>
    <pg:pager items="${backingBeanScope.searchClient.searchResults.totalResults}"
    maxPageItems="${backingBeanScope.searchClient.searchResults.maxPageItems}"
    maxIndexPages="${backingBeanScope.searchClient.searchResults.maxIndexPages}"
    isOffset="${backingBeanScope.searchClient.searchResults.isOffset}"
    export="offset,currentPageNumber=pageNumber"
    scope="request">
    <pg:param name="maxPageItems"/>
    <pg:param name="maxIndexPages"/>
    <input type="hidden" name="pager.offset" value="${backingBeanScope.searchClient.searchResults.isOffset}"></input>
    *<pg:index >*
    *</pg:index>*
    <c:forEach items="${backingBeanScope.searchClient.searchResults.results}"
    var="result">
    </c:forEach>
    </pg:pager>
    </div>
    </af:panelGroupLayout>
    </af:group>
    </f:facet>
    </af:pageTemplate>
    </af:form>
    </af:document>
    </f:view>
    <!--oracle-jdev-comment:auto-binding-backing-bean-name:backing_oracle_webcenter_portalapp_pages_untitled1-->
    </jsp:root>

    PeterBreis0807 wrote:
    Are you having trouble with tabs in a list?
    You haven't said so.
    In lists you have to use option tab, otherwise it just changes the list level.
    Peter
    I guess what you were hoping but you missed the point.
    Yvan KOENIG (VALLAURIS, France) vendredi 20 janvier 2012
    iMac 21”5, i7, 2.8 GHz, 12 Gbytes, 1 Tbytes, mac OS X 10.6.8 and 10.7.2
    My Box account  is : http://www.box.com/s/00qnssoyeq2xvc22ra4k
    My iDisk is : http://public.me.com/koenigyvan

  • Jsp in javascript

    hi
    can we use jsp in javascript
    for eg:
    <script>
    if(flag)
    <% respone.sendRedirect("--"); %>
    </script>
    or is there any other way of doing this type of things
    this is only an example.
    thx
    -jay

    You can use JavaScript in a JSP. JavaScript usually runs on client. You can also use Java in a JSP. Here is sample code:
    <%@ page import="java.util.*" %>
    <%
    Calendar cal = Calendar.getInstance();
         int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
         int hourOfDay = cal.get(Calendar.HOUR_OF_DAY);
         int minuteOfHour = cal.get(Calendar.MINUTE);
         if (((dayOfWeek == 7) & (hourOfDay == 23) & (minuteOfHour > 29)) || ((dayOfWeek == 1) & (hourOfDay == 0) & (minuteOfHour < 31))) { %>  
    <jsp:forward page="file:///M:/Studio/projects/som/html/IC_0019.htm" />
    <% } %>

  • Can I have a JSP  inside another JSP??

    if so,
    say, I have a JSP inside another JSP then,
    how many servlets r generated by the JSP engine??

    Yes U can have JSP inside another JSP, ofcourse using jsp:include and in that case two servlets will be generated. Thats what i feel that happens.

  • 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.

  • Jspc jsps inside WEB-INF?

              jspc skipped jsps inside web-inf folder (eg /webapp/WEB-INF/index.jsp) if -compileAll
              is specified. Is there any way to compile all jsps in a webapp without compiling
              one by one?
              thanks
              

    How about a look into the doc?
    1) http://www.oracle.com/pls/topic/lookup?ctx=fmw121200&id=ADFFD21876
    2) http://www.oracle.com/pls/topic/lookup?ctx=fmw121200&id=ADFFD22049
    3) http://www.oracle.com/pls/topic/lookup?ctx=fmw121200&id=ADFFD1815
    Timo

  • JSP language javascript

    What is the problem?
    <%@ page language="javascript" %>
    <%
    var i;
    for ( i=1; i<5; i++ )
    out.println("JSP whit JavaScript <br>");
    %>

    What is the problem?
    <%@ page language="javascript" %>
    <%
    var i;
    for ( i=1; i<5; i++ )
    out.println("JSP whit JavaScript <br>");
    %>The <% and %> tags indicate a Java scriptlet.
    "var" is JavaScript syntax, the rest is Java.
    out.println is a Java method.
    If you want to do your loop in JavaScript then it would
    be like this:
    <script>
    for ( var i = 1; i < 5; i++ )
    document.writeln("JSP whit JavaScript <br>");
    </script>

  • Crystal Report Images Not Showing - JSP inside /WEB-INF folder

    Hi Experts,
    I am using Crystal report for Eclipse and also using Struts2 and tiles framework combination.
    The problem is when viewing the report all I've got is red X on all images and the graph image also not showing. This is when I use tiles and my jsp is inside the web-inf folder.
    This is my struts link: href="s:url value='/report/reportOpen.action?report=1'
    I've checked that the path to the viewer generated HTML is not correct. see code below.
    src="../../../crystalreportviewers/js/crviewerinclude.js"
    But when I test to access a simple jsp viewer that resides on the web root folder, this works fine but of course this is not what I want to have. I need to have my banner and menus on top of the report page (using tiles)
    This is my jsp link: href="s:url value='/ReportViewer.jsp?report=1'
    Viewer generated HTML below.
    src="crystalreportviewers/js/crviewerinclude.js"
    This might be a common problem and that you can share to me your solution.
    Note: I removed the script tags because I can't submit this entry.
    Thank you  in advance,
    Regards,
    Rulix Batistil
    Crystal Report Images Not Showing - JSP inside /WEB-INF folder

    Hi Saravana,
    After a few experimentation from your idea i was able to figure out the problem and now it is working.
    I don't have to copy the folder to where my jsp resides but still maintains it in the root location:  web/crystalreportviewers
    The changes should always be in web.xml.
    1st: change the crystal_image_uri value to ../crystalreportviewers
    2nd: change crystal_image_use_relative value to "web"
    Change to "web" instead of webapp because that is what I named my web root folder.
    <context-param>
              <param-name>crystal_image_uri</param-name>
              <param-value>../crystalreportviewers</param-value>
         </context-param>
         <context-param>
              <param-name>crystal_image_use_relative</param-name>
              <param-value>web</param-value>
         </context-param>
    Thank you. You showed me the way on how to solve the 3 day problem.
    BTW, my next problem is when clicking on any buttons prev/next/print/export, I got this error HTTP Status 404.
    Well, at least for now I can view my initial report.  I just need to figure out the next issue and with the help of the great people here in the forum.
    Thanks a lot.
    Regards,
    Rulix
    Edited by: Rulix Batistil on Nov 26, 2008 7:27 AM

  • Include a JSP inside another JSP

    Hi SDN,
    I am stuck with a problem. There is a JSP file available. In this JSP I have to add some more fields. But when I try to ad new fields I am getting a Portal Runtime Error stating that "Code Too Large". So now I thought of putting the new code in another JSP and include that JSP inside my main JSP. Here I cannot use <@include file="..."> because this finally compiles both the JSPs as one.
    So I tried to use <JSP:include>. Some one please help me with how to include a JSP inside another using <JSP:include>. Here both the JSPs are having HBJ content inside.
    I know that <jsp:include page="relPathOfChild.jsp"/> will include the child.jsp into my main jsp. Problem is both the JSPs are having HBJ content, so If I dont declare <hbj:content> tag inside the child jsp, it is throwing an error. But If I declare a <hbj:content> tag inside my child jsp, only child content is coming and main jsp content is not coming.
    Please help me..
    Regards,
    SrinivaS

    Hi,
    This Problem is solved. Now I am able to include a child JSP inside the parent JSP. But now the problem is,
    This Parent JSP will have 8 tabs. Now my chils JSP should come inside 7th tab.  but it is coming above the parent JSP.
    Below is how I am including my child JSP.
    <% try{ if(isCAR){
         %>
                   <tr>
    <jsp:include page="/pagelet/CAREligibility.txt" />
                   </tr>
                <%} } catch(Exception e) {}%>
    Please help.
    Regards,
    SrinivaS

  • 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.

  • 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:
    spallared

    can 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

  • JSP , bean, JavaScript

    I have a page that uses a bean, myBean. There is a method inside myBean named getOccupation() and a property String Occupation. the getOccupation returns the Occupation to the page. The Occupation String is gotten from a database.
    I also have a form in the jsp page named myForm and a select field named Occupation.
    The idea is, get the Occupation from the database, return it to the jsp and make the select select the corresponding to the String gotten from the database.
    I'm trying to mix javascript with java here
    javascript to compare the current values of the Options in select to the Occupation and select it but it keeps giving me the error.
    <script>
    blabla javascript
    <% myBean.getOccupation()%>
    </script>
    That gives an error, anyone can help?
    thx
    Dewi

    I think the below code might help you.....
    I tried to reproduce your problem.....
    <%!
         String selectValue = "1";
    %>
    <html>
         <head>
              <title>Test Page </title>
              <script language="JavaScript">
                   function as(){
                        obj = document.form1.test;
                        for (i = 1; i < obj.length; i++){
                             if (obj.value == '<%=selectValue%>')
                                  obj[i].selected = true;
              </script>
         </head>
         <body onload="as()">
         <form name="form1">
              <select name="test">
                   <option value="">---------select----------</option>
                   <option value="1">1</option>
                   <option value="2">2</option>
                   <option value="3">3</option>
                   <option value="4">4</option>
              </select>
         </form>
         </body>
    </html>
    I hope this works.....

  • How to call jsp in javascript

    i am trying to show a confirm dialog and when the user click on the ok button, i want it to call a method inside my .java file. what i want to do is something like this:
    <script>
    var ans = confirm("Are u sure you want to over write file);
    if(ans)
    //call the method doUpload
    else
    //do nothing
    </script>
    /////////////.java///////////////
    public class FileUploadBean{
    public void doUpload(HttpServletRequest req, HttpServletResponse res){

    Something along these lines ought to do what you want:
    <html>
    <body>
    <form name='foobar' action='foobar.jsp'>
    <script language='Javascript'>
    function askim() {
      if (confirm('Is you sure?')) {
        document.foobar.submit();
      } else return false;
    </script>
    <input type='button' value='Submit' onClick='askim()'>
    </form>
    </body>
    </html>
    Your mileage may vary.
    But the idea here is that the Javascript merely submits the form if the user clicks "OK" on the confirmation pop-up. Otherwise, nothing happens. The form is submitted to a JSP file which accepts the request, does something (such as call your Java class), then prints out some HTML in response.

Maybe you are looking for

  • CrystalRas Not Starting "Unable to create the Corba OSCA factory and register it on the eBus" Error

    Post Author: eric@labcorp CA Forum: Deployment The CrystalRas service on one of our two clustered servers is failing with a "Unable to create the Corba OSCA factory and register it on the eBus" error message.  Has anyone seen this error before?

  • Firefox Locks Up And Is "Not Responding" A Lot

    This has been going on for years. When I have 3 or 4 tabs, especially facebook open, and am watching a youtube video Firefox freezes up a lot. I just dealt with it but I'm starting to get sick of it. The only addons I use are DownloadHelper and AdBlo

  • Automatic PR from Consumption based Planning

    Dear all          While creating automatic PR from Consumption based planning, only quantity has to come,the price should be updated manually,How to do it,Kindly reply to this query

  • How to Colour the fields in the Result Set of the query

    Hi all, I am having a requirement wher the user want to view the queries results with some colour to the char in the result set. suppose customer is the row he want to view some customers with one color and some with different color. Is it possible i

  • Change document details for a particular incident

    Hi All, I have a requirement like we are creating a ticket through Help------>Create support message. And Ticket owners can update the ticket through crmd_order transaction and change the status from open to in process and so on. So when ever a user