How to write JSP code in Java Script Code

Hello friends
I have code like
<script language="JavaScript">
function f()
(some code is here)
</script>
Now i wants to put some JSP code in f()
So can i do this ? IF yes then how ?
(one solution may be make JSP function and call that JSP function from the f().So in that case how can i call JSP function from JavaScript??
If other method is there then please mail me

If it's a simple matter of mixing client-side code with server side code, it can be done so long as you're using the server-side to write the client-side.
For example:
<h1>Good Morning Mr. Phelps</h1>
<input name=anybodyFunction type=text>
<% if (userIsAdmin) { %>
<input name=adminOnlyFunction type=text>
etc.
<% } %>
<h1>This browser will self-destruct in ...</h1>
That's JSP (inside the <% %>) mixed with HTML.
Javascript goes 100% on the client-side. If you're writing JSP with inter-mixed HTML, you might have to inter-mix the java-script.
For example: Suppose you need to validate the form. "adminOnlyFunction", among others, is a mandatory field, and you want the Javascript to only submit the form if all mandatory fields are set. Well, if the user is NOT an administrator, then that field WILL be left blank.
One way to handle that is with mixing JSP/HTML/Javascript on the SERVER side.
<h1>Good Morning Mr. Phelps</h1>
<input name=mandatory1 type=text>
<input name=optional1 type=text>
<% if (userIsAdmin) { %>
<input name=adminOnlyFunction type=text>
<% } %>
<input name=submit type=button value=Submit onClick="checkit()">
etc. etc.
<script language=Javascript>
function checkit() {
var f = document.form;
if (
� � f.mandatory1.value == ""
� � || f.mandatory1.value == ""
� � || f.mandatory2.value == ""
<% if (userIsAdmin) { %>
� � || f.adminOnlyFunction.value == ""
<% } %>
� � � � ) {alert ("Hey! You left out a required field!!");}
etc. etc. etc.
I imagine THIS might be what is meant by "mixing JSP with Javascript", and in this particular fashion, it can be done. What you're doing is making decisions on the server side over what to write out to the client. That client code can make further decisions based on user input.
However, once it's on the client side, you can not have anymore JSP code. The client NEVER runs JSP code.

Similar Messages

  • How to Use the JAVA SCRIPT code in .htm page of the component

    Hi .
    In my requirement i have to use Java Script Function in .htm code ..how to use the java script code and functions in .htm???
    thank you
    B.Mani

    Check this document  [Arun's Blog|http://wiki.sdn.sap.com/wiki/display/CRM/CRMWebClientUI-TalkingwithJava+Script]
    Regards
    Kavindra

  • How to Include JAVA script code in SAP BI7 web Reporting?

    How to Include JAVA script code in SAP BI7 web Reporting?

    In nw2004s there is a new web item called "Script" web item which lets you add javascript code. When you add javascript code in this web item, you don't need the opening and closing <script> tags...
    Hope it Helps
    Chetan
    @CP..

  • Display pop ups in the jsp by using Java script

    Hi
    can any body say ,how to display pop ups in the jsp by using Java script ?

    that's correct. You can use the below code for AJAX request.
    <script type="text/javascript">
    var httpObject = getHTTPObject();
    //create XMLHttpRequest object
    function getHTTPObject() {     
         var xmlhttp;
         if (window.XMLHttpRequest) // if Mozilla, Safari etc
              xmlhttp = new XMLHttpRequest();
         else if (window.ActiveXObject){ // if IE
              try {
                   xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
              catch ( e ){
                   try{
                        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                   catch ( e ){}
         return xmlhttp;
    //define the function to send the request
    function sendRequest(){
        var currDesc = document.getElementById("description").value;
        var URL =  "manageMaintAction.do"; //action mapping in your struts-config
        var queryString = "currDesc="+escape(currDesc); //get the currDesc value in your action class like request.getParameter("currDesc")
        httpObject.open( "Post", URL, true );
        httpObject.onreadystatechange = cbFn;
        httpObject.setRequestHeader( "Content-Type", "application/x-www-form-urlencoded");
        httpObject.send(queryString);
    //callback fn
    function cbFn() {
        if (httpObject.readyState == 4)
             if (httpObject.status == 200)
              var result = httpObject.responseText;
              alert(result);
    </script>

  • Dunno how to write JSP for login in......

    Can someone help mi on write JSP coding for login in page?i dun really know how how to write JSP coding. i m now doing a project on Private Driving instructor portal where people can register as trainee or instructor.now i want to write the JSP coding on the login page part.... when instuctor login it will go to a instructor's main page n if a trainee login it will go to a trainee's main page.Can someone help mi on this??? it's very urgent n important for mi.Please help mi.

    The easiest method I have found is to use a database to store the users details along with a flag indicating whether they are a trainee or an instructor. Upon logging in, you can use a bean to connect to the database and retrieve these values, then it is a simple matter of a jsp:forward tag to re-direct to the applicable page for trainee or instructor ...
    e.g.
    <pre>
    ***JSP PAGE ***
    <%@page language="java" buffer="32kb" import="jspclasses.customer.*" errorPage="./error.jsp"%>
    <jsp:useBean id="userBean" class="jspclasses.userInfoBean" scope="session"/>
    * Get user and pass from form variables. (if passed)*
    String user = request.getParameter("username");
    String pass = request.getParameter("password");
    * Retrieve fullname from session object. (if exists)*
    fullname = (String)session.getValue("fullname");
    String fwdPage = (String)session.getValue("fwdPage");
    if (fullname==null) {
         try {
         * If no session has been established then attempt to create one using *
         * the values passed through via form. If no values have been passed *
         * through then variables will equal null as opposed to empty strings. *
         * If null is evident, catch with NullPointerException. *
              if (user.equals("") || pass.equals("")) {
                   fullname = "Not";
              } else {
                   * Send values to method which validates users *
                   userBean.setUserInfo(user,pass);
                   * If an error was encountered within userBean the error *
                   * instance variable will != null. *
                   if (userBean.error == "") {
                        fullname = userBean.getFullname();
                   } else {
                        * Error was encountered so we set fullname to "Not", if *
                        * user was entered we re-display value and we instantiate *
                        * error variable to error value of userBean. *
                        fullname = "Not";
                        if (user!=null) uservalue=user;
                        error = userBean.error;
                        //out.println("Error is not null:<br>"+error+"<br>");
                   if (fullname!="Not") {
                        session = request.getSession(true);
                        session.putValue("fullname",fullname);
                        session.putValue("email",user);
                        session.putValue("user_id",userBean.getUserId());
                        session.putValue("user_type",userBean.getUserType());
                        session.putValue("sessionid",session.getId());
                        session.setMaxInactiveInterval(12000);
    ***END JSP***
    *** START BEAN ***
    public void setUserInfo(String user, String pass) {
    String stmtString = "";
    ResultSet rs = null;
    // Check to see if a valid connection is available
    getConnection();
    // If getConnection returns null then
    // connection successfully established
    if (error.equals("")) {
    try {
    // Create SQL string to be sent to database
    stmtString = "select * from serv_user where email = '" + user + "' and password = '" + pass + "'";
    // Execute SQL
    rs = stmt.executeQuery(stmtString);
    // Specify estimated rows to be returned
    rs.setFetchSize(1);
    // If a row is returned get first and last name
    if (rs.next()) {
    user_id = ((rs.getString("USER_ID")!=null)?rs.getString("USER_ID"):"");
    ("USER_TYPE_ID"):"");
    first_name = ((rs.getString("FIRST_NAME")!=null)?rs.getString("FIRST_NAME"):"");
    last_name = ((rs.getString("LAST_NAME")!=null)?rs.getString("LAST_NAME"):"");
    business = ((rs.getString("BUSINESS_NAME")!=null)?rs.getString("BUSINESS_NAME"):"");
    address = ((rs.getString("ADDRESS")!=null)?rs.getString("ADDRESS"):"");
    suburb = ((rs.getString("SUBURB")!=null)?rs.getString("SUBURB"):"");
    state = ((rs.getString("STATE")!=null)?rs.getString("STATE"):"");
    postcode = ((rs.getString("POSTCODE")!=null)?rs.getString("POSTCODE"):"");
    hom_phone = ((rs.getString("HOM_PHONE")!=null)?rs.getString("HOM_PHONE"):"");
    bus_phone = ((rs.getString("BUS_PHONE")!=null)?rs.getString("BUS_PHONE"):"");
    mob_phone = ((rs.getString("MOB_PHONE")!=null)?rs.getString("MOB_PHONE"):"");
    fax = ((rs.getString("FAX")!=null)?rs.getString("FAX"):"");
    email = ((rs.getString("EMAIL")!=null)?rs.getString("EMAIL"):"");
    pass_hint = ((rs.getString("PASSWORD_HINT")!=null)?rs.getString("PASSWORD_HINT"):"");
    else {
    error = "User <b>"+user+"</b> does not exist with specified password.<br>Please try again.";
    } // END : ResultSet = true
    } // END : TRY
    catch (SQLException sqle) {
    error = "<b>Error accessing database:</b><br> "+sqle.toString()+" - ORA:"+sqle.getErrorCode();
    catch (Exception e) {
    error = "<b>Error occurred in method setUserInfo()</b><br> "+e.getMessage();
    } // END : CATCH
    finally{
    closeConnection();
    try{
    rs.close();
    }catch(SQLException sqle){
    } // END : IF
    } // END : METHOD
    } // END : BEAN
    ***END BEAN***

  • Java Script Code not working properly for visios in sharepoint 2013

    Hi all ,
                 I have few visios and I am using the visio web part to display and to redirect from one visio to other visio I am using the java script code through content editor web part . 
    In share point 2010 it's working fine , I was able to redirect to all the visios and code is working fine .
    In share point 2013 its not the same , Its not working properly . only for the first time the code is working fine . once it goes to next visio the code stops working . 
    For example if i click in visio A it gets redirect to Visio B and its stops working , it wont allow to do any other steps . 
    I have checked with the URL its correct , I am not able to find any error also .
    Indresh

    This will be likely caused by the Minimal Download Strategy not registering the Javascript on the page reload. You can turn off the MDS feature to test this.
    You can either turn off MDS in your site, or register your Javascript functions with MDS to ensure they are called. To do this, you'll need all of your code to be wrapped in a javascript file (Embed this on the page using a <script> tag and
    inside that file in a function, which you then register with MDS as follows (I usually do this in the first line of the javascript file):-
    RegisterModuleInit("/SiteAssets/YourJavaScriptFile.js", NameOfYourFunction);
    Regards
    Paul.
    Please ensure that you mark a question as Answered once you receive a satisfactory response. This helps people in future when searching and helps prevent the same questions being asked multiple times.

  • How to increase font size in Java script alert message

    Is anybody know how to increase font size in Java script alert message
    THanks in Advance ....

    Hi,
    You can NOT do it with Javascript.
    You need an alternative solution: http://www.apex-plugin.com/oracle-apex-plugins/dynamic-action-plugin/popup-box_84.html
    Tobias

  • How to detect whether browser's java script  disabled or not from server

    How to detect whether browser's java script disabled or not from server side

    I would use a hidden parameter created by a javascript. if this is null, javascript is disabled...

  • How to save the user-defined Java source code

    Would you please tell me how to download all of the java source code in one software component.

    UDFs can be exported one by one as a .mte file...not at one go...

  • Java script code missing' comes up in a window when I try to batch process my images in photoshop.

    I have an imac version 10.9.4, Photoshop cs5.1. I'll select file-script-image processor and that is when the 'java script code missing' pops up. It used to work before I upgraded to the version 10.9.4. I called Apple and they don't know what to do. Now I'm here on the community site hoping someone can help. Not being computer savvy I don't understand anything I try to read about it.

    I finally found out that my 'McAfee SiteAdvisor' add-on was causing the problem for me. You can either disable it from your add-ons by clicking on tools, then add-ons and then disable it from your list of add-ons, or if you still wish to use it like I do, you can unistall it from your add-on list, and then download it from the official McAfee web site and then simply reinstall it... Since I've done this my firefox been loading faster, no annoying pop-up window when I launch or open a new tab. It was also crashing quiet often before I did this and that seemed to be fixed now.
    here is the link for the McAfee SiteAdvisor download from the official McAfee web site if anyone needs to download it again like I had to.
    http://us.mcafee.com/root/product.asp?productid=sa

  • How to write jsp select record from Oracle  divide per page , about 50 reco

    Dear Expert,
    How to write jsp select record from Oracle divide per page , about 50 record per page.
    Thank you very much.

    I wish I could, but there is no single sign on module available for Fusion, also, so called Fusion is yet another Word With Big Letters, behind it there is yet another OC4J ( now Oracle switched to Weblogic though) container with bunsh of Oracle apps residing in it.
    Generally speaking, neither Fusion nor Oracle Apps user database does not have any single authentication module available out of the box to integrate user database.
    It's a long sad story running straight from Oracle Apps 11.0.5.
    That's why I've created JAAS single sign on login module and used it ever since at OC4J 10.2 and onwards at OC4J 10.3
    Back to the topic: to develop Apps and test them externally using the session bean I've isted above, one need to copy certain libraries from Oracle Apps server, then add them as libraries for JDeveloper project.
    Here is the complete list:
    oracle.apps.fnd.cache
    oracle.apps.fnd.cache
    oracle.apps.fnd.common
    oracle.apps.fnd.functionSecurity
    oracle.apps.fnd.metadata
    oracle.apps.fnd.security
    oracle.apps.fnd.util
    oracle.apps.jtf.cache
    oracle.apps.jtf.security
    Edited by: Faceless on Nov 26, 2009 3:04 AM

  • Early 2008 mac pro 8 core quicktime videos opening in java script code

    When I try to view a quicktime video it opens in Java Script Code instead of playing the video on my early 2008 Dual Quad Core 2.8 Ghz. Mac Pro running OSX 10.5.8 

    That's not much to go on, but I doubt it has anything to do with it being a Mac Pro. Select the clip and Get Info (Cmd I) to see what application is named in the "Open with" drop down menu. If it is anything other than QuickTime player, change it and try again.  Also, repair your permissions...

  • How do I disable the "open java script' message box alert?

    How do I disable the 'open java script' message box message box alert?

    Bee Hong-
    What App is showing the message?  If it is Safari, go to Settings-Safari-JavaScript and turn it ON.
    If it is a different App, see if that App is in Settings and has a JavaScript option.
    Fred

  • How can i merge javafx code and java fxml code in a single project

    how can i merge javafx code and java fxml code in a single project.
    Please let me Know as soon as possible.

    Everything that it is possible to retrieve from a class file can be deduced from the class file definition.
    http://java.sun.com/docs/books/vmspec/2nd-edition/html/ClassFile.doc.html
    Sylvia.

  • Calling native Objective C code from Java Script

    Hi,
    I want to call native objective C code from Java script.
    I know one way by using : webView:shouldStartLoadWithRequest:navigationType
    Is there another way of doing same?
    Thanks,
    Ganesh Pisal
    Vavni Inc

    Are any of those threads calling java code? If yes then are you calling the Attach method?

Maybe you are looking for