Javascript string to jsp

Hi all, I have a JSP page with a javascript function that returns a string that I need to insert into my database. How would I go about getting a string from the javascript function to pass to jsp all on the same .jsp page? I can do this with an html with the javascript sent to a second jsp page, but I need this done all in one. Thanks

Hi all, I have a JSP page with a javascript function
that returns a string that I need to insert into my
database. How would I go about getting a string from
the javascript function to pass to jsp all on the same
.jsp page? I can do this with an html with the
javascript sent to a second jsp page, but I need this
done all in one. ThanksYou will have to send another request to the server. You can ask for the same page if you want, but javascript runs on the client, and JSP on the server. JSP is done and over before JavaScript ever starts. So to pass the value from the JavaScript to JSP, you will need to send it via a parameter to the JSP page when making another request.

Similar Messages

  • Passing javascript values to jsp without refreshing the page

    Hi,
    How do u pass a value of a javascript variable to the jsp without refreshing the page ?
    For example, a file called test.jsp in which a javascript variable x contains value 254. I need to pass the value of x to a method declared in test.jsp(same page).

    Hi Mona,
    when i say refresh i do mean a blink of the browser.
    This is a small example i wrote to show you how you can pass javascript varables to JSP variables. If you don't want the refresh to be seen by the user just include this code in a hidden frame on a page and instead of refreshing the entire page, refresh the hidden frame.
    i have to say, i didn't test the code so i don't guarantee it's flawless.
    if you need an more detailed example just tell me, i'll create one, but it won't be for today :)
    <html>
    <head>
         <title>Log in to the system</title>
    </head>
    <body>
    <script>
    //we retrieve the parameter 'user' from the URL
    <%
      String username = request.getParameter("user");
    %>
    var user = "<%= username%>";
    //check if there is a username in the URL
    if(user=="null")
      //there is no username so we log the person in as a guest
      user="guest";
      //we refresh the page and set the user parameter to 'guest'
      //the parameter now contains the javascript variable 'user'.
      //The parameter can be read by the JSP (see the top op this script).
      //This way we gave the javascript variabele to the JSP variable
      location="login.jsp?user="+user;
    else if(user=="guest")
    {  alert("Welcome "+user+", I hope you like this site"); }
    else
    {  alert("Welcome "+user+", I'm glad to see you again"); }
    </script>
    </body>
    </html>

  • How can i assign a Javascript variable to JSP variable

    Hi guys
    how i can assign a javascript variable to jsp expression.,
    e.g.,
    <input type = "button" value = "Add more" onclick = "return submitform1('<%=s%>')">
    function submitform1(String s)
          var s1 = s
    document.form1.action = "../intimation.do";    /* Here i want to pass the value s1 to jsp or servlets without using hidden fields and Query string*/
           document.form1.submit();
          return false;
    /*  i want to pass the values thru session whether it is possible */
    pls give sample code
    Reply
    Marimuthu

    You don't have the session.
    All you have is HTTP.
    The only way to communicate from the client to the server is via an HTTP request. The only way to send a value like that is with a parameter.
    Using a form with method="submit" as mentioned will pass the parameters without displaying them in the url bar (is that what you wanted?)

  • Passing JavaScript value to Jsp

    Hi,
    Any idea how to pass a value from javascript to jsp page when the page gets load on browser.
    I use below code but an event is require to pass the value. Is there any code that pass automatically the value from javascript to jsp.
    <html>
    <head>
    <title>Passing Javascript value to Jsp</title>
    <script type="text/javascript" language="javascript">
    var scriptVar = "Noy"
    var WinNetwork = new ActiveXObject("WScript.Network")
    document.write (WinNetwork.username)
    document.index.hiddenTextBox.value = WinNetwork.username
    </script>
    </head>
    <%
    String jspVar = null;
    if(request.getParameter("submit") != null){
         jspVar = request.getParameter("hiddenTextBox");
         out.println("Jsp Var : " + jspVar);
    %>
    <body>
    <form name="index" onSubmit="index.jsp" method="post">
    <input type="hidden" name="hiddenTextBox"><br>
    <input type="submit" name="submit" value="Submit">
    </form>
    </body>
    </html>
    Thanks,
    ~ukbasak

    JSP/Java runs at the server side, produces a HTML page, sends it to the client side and then stops running.
    HTML, containing under each CSS and JS, arrives at the client side and runs at the client side only.
    To invoke JSP/Java using HTML you need to fire a request to the server side. That can be either a plain vanilla <a> link, a <form> to be submitted or an asynchronous Ajaxical request.
    That said, the use of ActiveX in web applications is discouraged. It's a Microsoft IE proprietaty. With other words, it isn't and won't be supported by all alternative browsers which the other half of the world is using.

  • I want to assign the value of a Javascript variable to JSP Variable

    I want to assign the value of a Javascript variable to JSP Variable .. for example :
    <%
    Bla Bla Bla
    %>
    <script>
    var JavaScriptVariable="hello"
    </script>
    <%
    String JSPVariable=// The Value of JavaScriptVariable ;
    %>
    How can i do that ??
    Thanks

    >I want to assign the value of a Javascript variable to JSP Variable
    cannot be done.Friend try to understand concepts properly Javascript is always excuted by the browser @clientside where as JSPCode is executed Websever(ServletContainer) @serverside.Through you are combining JSP Code blocks(Tags,Expressions,scriptlets...) & javascript under a single page webserver can only identify what is their under JSP Code blocks.
    Hope this could be an appropriate answer for your question.
    However,you can as well submit a request by encoding your URL with request parameters and the submit to the page and then collect it using request.getParameter(name).
    But under a single context state it is not possible
    REGARDS,
    RaHuL

  • Use a Message from a bundle in a JavaScript string?

    I cannot use an h:outputText in a JavaScript string, for example:
    function init()
    setTitle("<h:outputText value="#{msgs.title}"/>");
    How can I get a text string from messages.properties that I want to use in some client side JavaScript code?
    Thanks in advance,
    Sam

    Hi Sergey,
    I followed your methos but got the following error msg:
    root cause
    java.lang.IllegalStateException: Component javax.faces.component.UIViewRoot@7dcf98 not expected type. Expected: UIOutput. Perhaps you're missing a tag?
         com.sun.faces.taglib.html_basic.OutputTextTag.setProperties(OutputTextTag.java:90)
         javax.faces.webapp.UIComponentTag.findComponent(UIComponentTag.java:712)
         javax.faces.webapp.UIComponentTag.doStartTag(UIComponentTag.java:429)
         com.sun.faces.taglib.html_basic.OutputTextTag.doStartTag(OutputTextTag.java:155)
         org.apache.jsp.main_jsp._jspx_meth_h_outputText_0(main_jsp.java:185)
         org.apache.jsp.main_jsp._jspService(main_jsp.java:129)
         org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
         org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
         org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
         org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
         com.sun.faces.context.ExternalContextImpl.dispatch(ExternalContextImpl.java:322)
         com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:130)
         com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:87)
         com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:200)
         com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:117)
         javax.faces.webapp.FacesServlet.service(FacesServlet.java:198)
         com.stufftolet.view.util.SecurityFilter.doFilter(SecurityFilter.java:76)
         de.mindmatters.faces.spring.RequestHandledFilter.doFilter(RequestHandledFilter.java:117)
    My javascript function is like below:
              <script type="text/javascript">
              <!--
              function init(){
                   setTitle("<h:outputText value='#{main_msg.browser_title}'/>");
              // -->
              </script>     
    and the declared resource bundle:
    <f:loadBundle basename="com.abc.view.bundle.main" var="main_msg"/>
    and I got main_en.properties and main_zh.properties.
    I call the init() function like:
    <body onLoad="init()">          
    please help, Thanks !
    regards,
    kmthien

  • How can I access xml document from javascript whithin a JSP page

    how can I access xml document from javascript whithin a JSP page?
    I have a JSP that receives an XML document from a JavaBean, so I can access it within the entire JSP, but I need to access it from the javascript inside the JSP... and I have no idea how i can do this.
    Thanks in advance!

    The solution would only work on MS IE browsers, as other browsers do not support an XML DOM.
    It can be done, but you would be stuck with using the Microsoft broswer. If that is acceptable, I have some example code, and a book recommendation.

  • How to pass javascript variable to jsp function

    i want to check which table header (that is <th> in html )is clicked and based on that a jsp funtion do a query in database and should show records in sorted way according to which column head is clicked.
    Table is created in html.
    My function is
    Vector varray = workcaseid.getWorkcaseId(Long.parseLong(MasterAccountNumber),SelectedColumn);
    <table border="1">
              <th ><label onClick="<%SelectedColumn="workcase_id";%>">Workcase Id</label></th>
              <th><label onClick="<%SelectedColumn="status_id";%>">Status</label></th>
    <tr><td>etc</td></tr>
    </table>

    im using bean for business login, following mvc model,and i think mvc is one of good design practice to use.
    <jsp:useBean id="workcaseid" scope="session"class="beanFiles.SearchWorkcaseId" />
    varray = workcaseid.getWorkcaseId(Long.parseLong(MasterAccountNumber),SelectedColumn);
    just tell me whether it is possible to pass javascript variable to jsp variable or not.i can do it by using hidden input type,using form and submit button.

  • Special characters in a javascript string...

    Hey folks, in the javascript project I'm working on, there's a requirement that an SOH character (start of header, #1 in the ASCII character set) be included in a string. Does anybody know how that character can be inserted in a javascript string? Thanks in advance.

    Thanks to both of you for your good advice. One last question: the project that I'm working on involves exporting the contents of an Adobe InCopy CS2 document to a text file. Before the export occurs, I insert a line that starts with ACSII character 1 and ends with ASCII character 2 , at the top of the file. This tells a subsequent process how and where to push the file. The export is working as it should. However, the ACSII control characters are not exported with the text file. Any thoughts on how, or if, this possible?

  • How can we  use java variable in javascript code on JSP page?

    How can we use java variable in javascript code on JSP page?
    Pls help

    Think about it:
    JSP/Java is executed on the Server and produces HTML+JavaScript.
    Then that HTML+JavaScript is transfered to the client. The client now interpretes the HTML+JavaScript.
    Obviously there's no way to access a Java variable directly from JavaScript.
    What you can do, however, is write out some JavaScript that creates a JavaScript variable containing the value of your Java variable.

  • Passing JavaScript values to JSP variables

    Can any body correct the follwing code
    <Script language="JavaScript">
    function test( x )
    <%
    int num = x;
    num = num * 2;
    %>
    v.value = "<%out.print(num);%>";
    <input type="button" name="b" value="test" onClick="test(5)">
    <input type="text" name="v" value="0">
    In short, I am trying to pass JavaScript value to JSP variable. I hope that it is possible to do that. If it is possible then how can I do it. I want to assing the variable x passed to the JavaScript function called test to the JSP variable called num.
    Regards,
    Ageel

    Thank you for your reply,,,
    I think then the only way to do it is to post the
    value on the server and then use request.getParameter
    method in jsp code
    but the question now how can I post values to the
    server using JavaScript without reloading the pageyes... you can to it by create a new popup window which will submit the value to server after page was loaded... then, server return a value to the same window in html/jsp page which then using javascript to set it back to the opener and close up the window... however, this is not a good choice unless you have no other alternative...
    >
    There is other possible solution
    if I can get the text field value from the same page
    without reloading it that would work fine and will
    solve my problem, is it possible?yes... you can get the value from the textfield...
    for example :
    function showValueInTextField()
        alert(document.forms[0].elements["mytextfieldname"].value);
    >
    My final question> can jsp change things on the same
    page without reloading it. I mean can it work like
    JavaScript so that I can use it's internal functions
    instead of using java script :S
    not really know what you trying to say here...

  • How can I assign javascript variables to jsp or java variables.?

    How can I assign javascript variables to jsp or java variables.?

    See I have generated some variables in the javascript which is on the jsp page. I want to assgin these variables to the jsp vaiables. Or how can I access javascript variables from jsp on the same jsp page.

  • Get javascript variable in JSP

    Hi all,
    can anybody tell me- how to get javascript variable in JSP,
    in the same file (JSP).
    Is this possible.
    I can use JavaScript to get the value,
    but then I have no way to get that to the JSP code.
    Please give the appripriate answer with code.
    Thanks
    amitindia

    Hi all,
    Thanks for your quick response.
    So u are right that we can not call javascript variable
    in the same JSP. and pass them to the bean class.
    So what I did --- I get java script variable in another JSP using
    request.getParameter(); and then redirected to previous JSP.
    and I have solve my problem.
    Actually I had to call bean class and pass varible to the bean
    method but I was getting the same problem that I disscussed but now it
    has been solved.
    Thanks again for participation
    amitindia

  • Forwarding array of String to jsp

    Hi all
    I want to forward an array of string to jsp page. I use the following code:
    servlet:
    request.setAttribute("list", list);and
    jsp:
    <%  String[] symptomslist = (String[])request.getAttribute("symptomslist"); %>But the values in the array are null. The length is correct. Can anyone please help me in this?
    Thanks a lot.
    dude

    Hey Hey,
    Sorry,
    My code was suppose to be this:
    String[] list = (String[])request.getAttribute("list");Thanks for noticing. Can anyone still help me?
    dude

  • How to split  a string in jsp?

    I have a set of strings or names in ${form.temp.name}Is there anyway I can split a string in jsp or jstl by a newline "\n" or space "\\s" character and print them separately. Or Do i have to do something in my controller as I am using spring with jsp and jstl for my web application?
    Thanks.

    Yes I did the work as below. When I use some delimiters like ";", the code works. But for the newline character of carriage return it does nto work.
    <c:set var="str" value="${form.temp.name}"/>
                     <c:set var="delim" value=" \r\n|\\n"/>                
                     <c:set var="array" value="${fn:split(str, delim)}"/>          
                     <c:forEach var="token" items="${array}">
                         <p><c:out value="${token}"/> </p>
                     </c:forEach>                Icidentally for the same element, when I try to split in java with the same delimiters, it is working. I am surprised why it is not working?

Maybe you are looking for