How to combine JavaScript within JSP statements

I have trouble figuring out how you can get a value from your JavaScript and insert it into a JSP Object.
I have a JavaScript function like this:
function setCookie(user) {
<%
Cookie cookie[] = request.getCookies();
for (int q = 0; i < cookie.length; i++)
     if (cookie[q].getName().equals("username")) {
     cookie[q].setValue(user);
     break;
%>
I wish to add the user variable of the JavaScript into the cookie[q]'s value. Is this possible? If so could anyone please help me in telling how to do this or maybe an alternative method.
Thank You

A call to JavaScript goes to the browser on client. A JSP request goes to the JSP container on the server. Therefore to
get a value from your JavaScript and insert it into a JSP Object.will require a request to the server and response back. You could use a form to send the "user" value to the server and the JSP could send response to the browser to set the cookie.
or maybe an alternative methodWhy don't you use a pure JavaScript solution. Your JavaScript function could set the cookie directly. JavaScript can manipulate cookies by using the "cookie" property of the Document object.

Similar Messages

  • Help me!! How to use JavaScript with JSP ??

    I am using JDeveloper and I created a screen in JSP which uses a bean for database connectivity and retriving info onto the page.
    The page has a ListBox where list items are populated from the database.My requirement is
    whenever the list is changed the page shuold be refreshed with the selected item info.
    I tried to use 'JavaScript' for triggering the event with 'onChange' event of the ListBox.But the event is not getting invoked. I think JavaScript is not working with JSP.
    Please help me with how to Use javaScript with JSP or any other alternative where I can meet my requirement.
    I have one more question...I have gone through the JSP samples in OTN and I am trying do download the sample 'Travel servlet' which show list of countries...etc
    I have also gone through the 'readme' but I don't know how to extract .jar file.
    I would be great if you could help me in this.
    Thanks!!
    Geeta
    null

    We have a similar need. We have used Cold Fusion to display data from Our Oracle Database. We have a simple SElect Box in HTML populated with the oracle data. When someone selects say the State of Pennsylvania. then we have an On change event that runs a Javascript to go get all the cities in Pennsylvania.
    Proble we are having is that inorder for the Javascript to work , we currently have to send all the valid data.
    Do you know of any way to dynamically query the the Oracle database in Javascript

  • How to combine javascript, flex

    Hi,
    This is Siva Kumar. I am begginer to adobe flex. I have lot
    of doubts regardng flex. Actually I have different requirements for
    that I think I have to combine javascript and jsp with Flex. Is it
    possible to combine/integrate javascript code with flex. If
    possible anybody help me to in this issue.
    Thanks & Regards,
    Siva Kumar

    A call to JavaScript goes to the browser on client. A JSP request goes to the JSP container on the server. Therefore to
    get a value from your JavaScript and insert it into a JSP Object.will require a request to the server and response back. You could use a form to send the "user" value to the server and the JSP could send response to the browser to set the cookie.
    or maybe an alternative methodWhy don't you use a pure JavaScript solution. Your JavaScript function could set the cookie directly. JavaScript can manipulate cookies by using the "cookie" property of the Document object.

  • How to combine servlet and jsp

    I'm doing a project. My friend using jsp. and i using servlet..
    we are confused, how to combine servlet and jsp. or we can just use redirect??
    but it's still doesn't work properly...thanks for your helpp

    You can use RequestDispatcher interface for calling a JSP from a Servlet, or vice-versa.
    Following is the code for sending output to a JSP page from a servlet:
    javax.servlet.RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(�/Ashu.jsp�);
    request.setAttribute(�Name�,�Ashutosh�);
    dispatcher.forward(request,response);
    - Ashutosh

  • How to genarate javascript from jsp?

    how to genarate javascript from jsp?
    Edited by: coolsayan.2009 on May 12, 2009 6:21 AM

    coolsayan.2009 wrote:
    [got an example|http://www.ibm.com/developerworks/web/library/wa-aj-simplejava1/index.html] but can you say all this specifically because i am not familier with AJAX.and i want to generate a javascript random number and by jsp i want to send it to user email.once user got the number it will be checked wheather he got it or not in next page say check.jsp if it this entry is right he will be grant to access the his account....
    What does AJAX have to do with the rest of this question? And why do you want to generate a number in JavaScript at all? If you are trying to confirm a working email address, which is what I think you are trying to do then leave that all on the server side. Generate the number in the servlet, mail it, etc. Neither JavaScript nor AJAX are any part of that.

  • How to insert Javascript within Javascript ?

    I have a simple problem.
    I want to insert Javascript within Javascript ???
    Seems weird !!!
    Here's the scenario :
    I have created a JSP in which I have a function that Submits the main form in the main window.
    Here's the function :
    function SubmitContent()
    document.f1.method='post';
    document.f1.action='http://localhost:8080/examples/sherbir/texteditor2/page2.jsp';
    document.f1.submit();
    and here's the form description :
    <form name='f1'>
    But before that, on clicking the submit button in the main window, I am opening a child window to perform a few operations as follows :
    <input type="button" name="bttn_preview" value="Preview" onClick="javascript:SeePreview()">
    Here's the SeePreview() function which opens the child window:
    function SeePreview()
    var mywin=window.open("","","menubar=no,toolbar=no,scrollbars=yes,width=800,height=450");
    mywin.moveTo(0,50);
    mywin.document.write('<input type=button value="Make more changes"
    onClick=javascript:window.close()>');
    mywin.document.write('<input type="submit" name="child_bttn_sub" value="Proceed" onClick=self.close(); self.opener.SubmitContent();>');
    The child window in turn has a submit button as defined above.
    On clicking this button, I want the child window to close and hence submit the parent form also.
    It's not happening !!
    I even tried changing the order of the two statements in the OnClick event of the submit button in the child window.
    I also tried self.opener.document.forms[0].submit()
    None works.
    Where's the problem ??
    How do I remedy the situation ?
    Please Help.

    Not satisfiedAnd you won't be till you ask the right people for an answer. This is Java, and JavaServer Pages (JSP), not Javascript. If you go to a Javascript forum you will have a better chance of finding people who know more Javascript. Makes sense, doesn't it?

  • JavaScript within JSP

    Hi all !!
    I'm stuck up.
    Is there any way by which i can actually embed JavaScript within a JSP file that contains no JSP code. Actually it is file with .jsp extention but from within it holds only java script inside <script> tags.
    The prerequisite is there should be no performance implications... as this would be just a plain js file anyways.
    I need this coz i want to pick-up messages for alert from Resource bundle. For this i'am using <bean-el:message ...> tag. but using this in a plane .js file is not possible.
    How should i go about it.
    or
    Is there any better way to do this.

    You could put how much ever js that you need inside a jsp file. Theres no restrictions and given that you have to pick up messages using a tag, there's no other way out too.
    Other than the compilation time (which can be overcome by precompiling jsps), there's not much of a difference in the load time for a static html or html streamed from a jsp process. Ofcourse if you use the 'src' tag to load you js, each 'src' results in a round trip. However that's true of even static html pages.
    cheers,
    ram.

  • How to set client within SQL statement without using another pl/sql stmt.

    I have a following select statement
    SELECT SUM (w.prior_forecasted_costs + w.prior_committed_costs)
    FROM xxsuf.job_cost_summary_table w,
    apps.pa_periods p,
    pa.pa_resources bz,
    pa.pa_resource_list_members cz,
    pa.pa_tasks dz
    WHERE w.project_id = z.project_id
    AND w.task_id = dz.task_id
    AND dz.task_number '98000'
    AND w.resource_list_member_id = cz.resource_list_member_id
    AND cz.resource_id = bz.resource_id
    AND NOT EXISTS (SELECT NULL
    FROM pa.pa_tasks zz
    WHERE zz.parent_task_id = dz.task_id)
    AND w.resource_list_member_id != 1000
    AND p.period_name = w.pa_period
    AND p.current_pa_period_flag = 'Y'
    Above select statement uses pa_periods view which only works when I set my client using "exec DBMS_Application_Info.set_client_info(83);" in Toad or SQL*Plus session.
    I was wondering how can I achieve it within select statement. so that I don't have to use another PL/SQL statement to set my client. Is there anyway to set client with my org id within above select statement ?
    Please advise.
    --Rakesh                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    You can simply create a function which calls dbms_application_info and use that in your sql statement as in
    SQL> create or replace function set_client_info (i_info varchar2)
       return varchar2
    as
    begin
       dbms_application_info.set_client_info (i_info);
       return i_info;
    end set_client_info;
    Function created.
    SQL> create or replace view v_emp
    as
      select * from emp where empno = to_number(sys_context('userenv','client_info'))
    View created.
    SQL> select ename from v_emp where set_client_info(7788) is not null
    ENAME    
    SCOTT    
    1 row selected.
    SQL> select ename from v_emp where set_client_info(7900) is not null
    ENAME    
    JAMES    
    1 row selected.

  • How get ServletContext from within JSP-page

    Hi! I was wondering how to get the ServletContext from within a JSP-page?
    /Ernstad

    The "application" implicit scripting variable is the same thing. e.g
    application.getAttribute(...);

  • Again combining javascript and jsp

    can i do the post methode of a form inner a javascript function?
    i want first check whether the reqiered fileds r filled and the do the post action.
    Andre

    Yeah that is really quite simple....
    function FormValidation()
    //do Validation stuff here
    document.MyForm.submit;
    <HTML><BODY>
    <input type=submit name=submit value="Submit
    onclick = "FormValidation(); return false;">
    The return false will cancel the submit action.
    null

  • Javascript popups in an if-else jsp statement

    hey there!
    i got a question...how can i get a jsp popup box in my jsp if-else statement??
    if (rs.next()) {
    String dbValue = rs.getString("Password");
    if (password.equals(dbValue)) {
         response.sendRedirect("PersonalDetails.jsp");
    else {
         //say its wrong
    else {
         //say its not found
    that is my code. the popup boxes need to say user is not found or wrong.
    thanks!

    Try this.
    <%@ page import="java.sql.*" %>
    <HTML>
    <HEAD>
    <TITLE>Graduate Application Form</TITLE>
    </HEAD>
    <%
         Connection con      =      null;
         Statement st      =      null;
         ResultSet rs      =      null;
         String strOnLoadJS = "";
         try
              Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
              con = DriverManager.getConnection("jdbc:odbc:fypproject","","");
              st = con.createStatement();
              String email = request.getParameter("email");
              String password = request.getParameter("password");
              String query = "SELECT * FROM Login_Details WHERE Email_Address = '" + email + "'";
              rs = st.executeQuery(query);
              if (rs.next()) {
              String dbValue = rs.getString("Password");
              if (password.equals(dbValue)) {
              response.sendRedirect("PersonalDetails.jsp");
              else {
              strOnLoadJS = " onLoad=\"javascript: alert ('User / Password Mismatch');\"";
              //return false;
              else {
              strOnLoadJS = " onLoad=\"javascript: alert ('User not Found');\"";
              //return false;
    %>
    <BODY <%=strOnLoadJS%>
    </BODY>
    <%
         catch (Exception exp)
         finally
              try
                   if (rs != null)
                        rs.close ();
                   if (st != null)
                        st.close ();
                   if (con != null)
                        con.close ();
              catch (Exception exp)
    %>
    </HTML>

  • How to use JavaScript in Web bean generated JSP

    I want to do some simple JavaScript validations (for example, checking if a particular field is empty) in the JSP page rendered by the data web bean. Because the HTML is rendered by the bean, I'm not able to refer to the HTML controls in the JSP page. I'm not even able to refer to the form with the following standard piece of JavaScript code - "document.forms[0].control_name".
    Is anybody aware of how to use JavaScript with these rendered JSP pages?

    You just have to add it like and applet , including this line in your JSP or JSF
    <script src="http://dl.javafx.com/dtfx.js"></script>Then add the applet
    <script>
        javafx(
                  archive: "./resources/jar/Draw.jar",
                  width: 400,
                  height: 200,
                  code: "Draw",
                  name: "Draw"
    </script>./resources/jar/Draw.jar - is the path and the name of the jar

  • How to use Javascript array in the JSP

    hELLO Friends,
    I am creating an String array using the values
    in the list of a jsp page using Java script..
    How can I use this array in the same jsp
    file for processing...
    any help in this regard would be highly appreciated.
    thanks in Advance...
    ashish

    you cannot pass values from javascript to JSP without having to form-post to another JSP page.

  • How to do  validation in jsp using javascript

    how to do validation in jsp using javascript

    The same way you do with any HTML page.
    Catch the onclick/onsubmit event, do your validation in javascript and then allow/cancel the action as required.
    However this is javascript validation only - javascript can never call JSP code.

  • How can we call java control source methods within jsp

    Hi guys!
              How can we access java control source methods that are defined in java control projects within jsp.I am getting error when I tried to call java control source's methods in scriptlet of JSP page.Any help/suggestion is appreciated.
              Thanks
              -Chandu

    Uh, what?
    (And you are sure that it's not a Weblogic-specific question?)

Maybe you are looking for

  • Getting an error while deploying the Quiz application in NWDEV

    Hi, I am getting an error while deploying the Quiz application in NWDEV. Please check this error log. It looks that it is not getting the Question.properties file but the file is already specified in the desired location. Error log: Detailed Error In

  • Has anyone done a MacBook Pro Exchange?

    Hey guys, Just wondered if I could ask you guys what you think of getting a replacement for my MacBook Pro - it's well within warranty, and I'm having a fair amount of problems with it! 1) The fans sound like a card in a bicycle spoke - and when I ge

  • How to build a screen with master detail data

    Hi ,expert , Someone can teach me how to build a screen with master detail table ? I wnat to build a screen for user to maintain FERT group  and  FERT detail list  in one screen . just like this .. MASTER Block FERT1       FERT2  FERT3 DETAIL Block F

  • Invalid account error when doing an internal reconciliation

    Hi all. A client is having this issue with one of the users. when trying to do an internal reconcilation on a business partner..the user gets an error Invalid Account Code [Message 173-9] She tried to do the recon 3 times and got that error. They are

  • Sapscript - text position

    Hi friends! I'm making some changes in a copy of Sap form medruck. I have line with text and I used ',,' to space, but por minimal adjusts I'm trying with blanks spaces, but it don't take effects....why space is not moving the text? I'm using a defau