How to pass value from JSP to Javascript?

I want to pass 2 integers to Javascript to do checking? How can I do that?

Well, it is very simple, Follow these steps.
1. Have a form with fields
2. On submit validate the form using javascript
3. If the javascript returns false do not submit the form
4. if the javascript returns true submit the form
5. The destination jsp page will handle the db operations.
1. <form name="frm1" action="dbcheck.jsp">
<input type="text" name="txt1">
<input type="button" value="submit" onClick="return validate();">
</form>
put the above piece of code in the <body> tag
2. Upon submit the js function validate() will be called :
<script language="javascript">
function validate() {
if(document.frm1.txt1.value="") {
alert("enter text");
return false;
else {
document.frm1.submit(); // i am not sure whether the () after submit is required or not
put the above piece of code in the <head> tag.
3. Now when the submit happens, the control goes to the dbcheck.jsp
this is dbcheck.jsp:
<%
String str = (String) request.getParameter("txt1");
------other db operations go here --------
%>
"txt1" is the field name of the textbox from the form u previously submitted.
all da best

Similar Messages

  • How to pass value from jsp to java bean

    I have huge problem . How to pass value from jsp value to java bean.Please replay me soon

    Use the <jsp:setProperty> tag. There are several ways to use it. The one you probably want is:
    <jsp:setProperty name="bean_name"  property="property_name"  value="the_value_you_want_to_set"/>

  • Passing value from JSP to JApplet

    Hello,
    I am stuck up with a problem, can anyone please tell me how do i pass a value from a JSP page
    to a JApplet,
    and the parameter passed through JSP should be displaed in the JTextArea.
    It would be kindful if any of you could help.
    Thanks
    Sanam

    hello,
    thanks for reply.
    I know how to pass parameters from html,
    I want to pass values from jsp page,
    and i dono how to do it, may be we cann pass values through url connection but i dono how.
    if anone knows plz help me in solving this.
    i hvae posted my applet code.
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.JToolBar;
    import javax.swing.JButton;
    import javax.swing.ImageIcon;
    import javax.swing.JFrame;
    import javax.swing.JTextArea;
    import javax.swing.JScrollPane;
    import javax.swing.JPanel;
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    import java.net.*;
    import java.sql.*;
    <applet code = "DocApplet" width = 500 height =5000>
    </applet>
    public class DocApplet extends JApplet
         private JPanel jp;
         private Container cp;
         private JTextArea jt;
         private JToolBar tb;     
         private JScrollPane sp;
         private String annotation;
         private String url;
         private Connection con;
         private Statement stmt;
         public void init()
              jp = new JPanel();
              cp = getContentPane();
              jt = new JTextArea();
              tb = new JToolBar();
              sp = new JScrollPane(jt);
              repaint();
         public void start()
              jp.setLayout(new BorderLayout());
              jp.add(tb, BorderLayout.NORTH);
              jp.add(sp, BorderLayout.CENTER);
              jt.setBackground(Color.BLACK);
              jt.setForeground(Color.WHITE);
              setContentPane(jp);
              addButtons(tb);
              repaint();
         public void run()
              repaint();
         public void paint()
         private void addButtons(JToolBar tb)
              JButton button = null;
              button = new JButton("Save");
              button.addActionListener(new ActionListener()
                   public void actionPerformed(ActionEvent e)
              tb.add(button);
    }

  • How to Pass values from XML to JSP??? Urgent Please Help me

    Hi guys,
    I am new to XML, I want to pass values from XML to JSP. I have a xml file with attributes, I should send this values to a JSP file. How is it??? Please Help guys.... its very urgent. Please send me how to do it with an example or atleast any urls related that....
    Looking for ur favourable reply.
    Thanks in advance,
    Sridhar

    in a servlet :
    parse your xml file (see how at the end of the post) and
    put the values you want in the request attributes
    request.setAttribute("value1", value1);
    ...redirect to the jsp
    in the JSP:
    get the wanted attributes:
    String value1=(String)request.getAttribute("value1");To learn how to parse a xml file, pay a look at this page, it explains how to read the XML document to build an object representation, and then how to navigate through this object to get the data
    http://labe.felk.cvut.cz/~xfaigl/mep/xml/java-xml.htm

  • Passing value from JSP to scriptlet

    Hi
    I am trying to find a way to pass a value from jsp to the scriptlets, i.e.
    <c:set var="testValue" value="123" />
    <%
    System.out.println(testValue);
    %>
    the above code just demonstrates what I was trying to achieve, by passing the value from the jsp into the scriptlet.
    Can someone tell me if there's an easy way to do this?
    Thank you.

    Note, using scriptlet code on your page is generally something to be avoided. 99% of what you should be doing on a JSP page can be done with EL/JSTL. If you can't do it with EL/JSTL then it probably belongs in a servlet/bean.
    I always aim for 100% scriptlet free jsp pages.
    Having said that, I can still answer your question: EL attributes are stored in the scope - page, request, session, application
    ${testValue} is equivalent to pageContext.findAttribute("testValue").
    The <c:set> tag example doesn't specify a scope, so therefore you could get it like this:
    <c:set var="testValue" value="123" />
    <%
    String testValue = (String)pageContext.getAttribute("testValue");
    System.out.println(testValue);
    %>alternatively exploit the feature of the useBean tag that creates a scriptlet variable:
    <c:set var="testValue" value="123" />
    <jsp:useBean id="testValue" type="java.lang.String"/>
    <%
    System.out.println(testValue);
    %>Note that the EL variable and the Scriptlet variable are initially pointing at the same String.
    But changing the string in scriptlet code will change the value it is pointing at, while leaving the EL variable untouched.
    If you have a List in scope, and sharing it between EL and scriptlet variables then any changes to the list would be reflected because they both point at the same List object.
    cheers,
    evnafets

  • How to pass value from the jsp file to a java bean

    I have huge promblem .I want to pass value of combo box to bean file to set my database contecting.The is how i call function to pass database to the bean file
    <%db.setDatabase(database);%>are coding to set my databse connection
    private String database;
        public Conn(){
         try{
                   Class.forName("org.gjt.mm.mysql.Driver");
                   DriverManager.registerDriver((Driver) Class.forName("org.gjt.mm.mysql.Driver").newInstance());
                   String data=getDatabase();
                   String url = "jdbc:mysql://localhost/"+data;
                   Connection conn = DriverManager.getConnection(url);
                   setConnection(conn);
              catch(SQLException e){
                   System.out.println(e.toString());
              catch(Exception e){
                   System.out.println(e.toString());
         public void setDatabase(String Database){
          this.database = Database;
         public String getDatabase(){
         return this.database;
         }     and Below are error produce
    Note: sun.tools.javac.Main has been deprecated.
    /mrs/system_menu.jsp:18: Method setDatabase(java.lang.String) not found
    in class bgoc.dbConn.Conn.
    db.setDatabase(database);
    ^
    1 error, 1 warning
    please help me soon. any that come to your will help
    thank you

    I have huge promblem .I want to pass value of combo box to bean file to set my database contecting.The is how i call function to pass database to the bean file
    <%db.setDatabase(database);%>are coding to set my databse connection
    private String database;
        public Conn(){
         try{
                   Class.forName("org.gjt.mm.mysql.Driver");
                   DriverManager.registerDriver((Driver) Class.forName("org.gjt.mm.mysql.Driver").newInstance());
                   String data=getDatabase();
                   String url = "jdbc:mysql://localhost/"+data;
                   Connection conn = DriverManager.getConnection(url);
                   setConnection(conn);
              catch(SQLException e){
                   System.out.println(e.toString());
              catch(Exception e){
                   System.out.println(e.toString());
         public void setDatabase(String Database){
          this.database = Database;
         public String getDatabase(){
         return this.database;
         }     and Below are error produce
    Note: sun.tools.javac.Main has been deprecated.
    /mrs/system_menu.jsp:18: Method setDatabase(java.lang.String) not found
    in class bgoc.dbConn.Conn.
    db.setDatabase(database);
    ^
    1 error, 1 warning
    please help me soon. any that come to your will help
    thank you

  • Passing value from JSP to Action in Struts

    Hi,
    I am populating JSP page with rows retrieved from the database and
    represented as a List of Beans in forEach loop:
    <c:forEach var="list" items="${OperationsForm.OperationsList}">
    <c:choose>
    <c:when test="${list.isCompleted =='Y'}" >
    <td width="100">Completed</td>
    <td width="100"> </td>
    </c:when>
    <c:otherwise>
    <td width="100">Pending</td>
    <td width="100"><input type="image" onclick="
    rowId=value; form.action='action.do?command=notify'"
    value="${list.OperationId}" />
    </td>
    </c:otherwise>
    </c:choose>
    </tr>
    </c:forEach>
    Have hidden field: html:hidden property="rowId" value="-1"/>
    User is clicking the button corresponding to one of the rows
    and I need to pass the value of that rowId to the Action class, so it does
    something in the database [action completed]
    Now how do I pass it , is that the right way of doing it with calling
    request.getSession().getAttribute(rowId) in the Action class ?
    As of now I am getting Javascript error "Object doesn't support this
    property or method", complaining about rowId=value;
    Using Struts 1.3
    Please help !
    TIA,
    Oleg.

    So what you are saying is that I should add rowId here:
    <input type="image" onclick="form.action='action.do?command=notify&rowId='
    ${list.OperationId}"/> , correct ?
    I am not sure that it will work, especially with Struts tag.
    I will probably try something like:
    <html:submit onclick="form.action='action.do?command=notify'" value="${list.OperationId}">
    I am relatively new to Struts, so now sure what will work or not and how to do it better. How do I catch the submitted value in the Action in either of these 2 cases, via action.getSession().getProperty("rowId") /
    action.getSession().getProperty("submit") ?
    I would probably do it as a URL rather than changing the action of the form.I will have to create a new action anyway to process that row [which is sending user e-mail regarding that row data/event].
    Is the id the only thing you have to pass in?
    Or do you need other values from the screen?Selected rowId is probably the only thing I care about, can access values from the Form in Action.
    Thank you,
    Oleg.

  • How to pass password from jsp to Applet

    Hi ,
    I can pass the user to applet like below. But password will be seen from view source.
    How can pass password without showing in the view source.
    <PARAM NAME="loginname" VALUE="<%=request.getParameter("loginname")%>">
    <PARAM NAME="loginpassword" VALUE="<%=request.getParameter("loginpassword")%>">
    Thanks in advance.
    Rockesh

    Or alternatively, determine why you need to pass the password on to the Applet.
    For example, if the Applet needs to log into a resource, it is much more secure to ask the user for a password then, as opposed to getting the password from a form, passing it on to the Applet and then having the Applet blindly relay the password to the server, the database, whatever.
    If the Applet doesn't need to do anything with the password, then I must question the wisdom of passing on the password in the first place.
    If the Applet uses the password to do authentication, then the best solution is to generate hashes of the password and compare those hashes as needed. This would make it much more difficult for someone to either eavesdrop on it, or guess it through random trial and error. We can take it one step further. When the JSP code is executed - generate a one time unique password that's extremely long, at least 128 characters. Embed the password in the resulting HTML page as a hidden field and seed the Applet with the password. That would tie the Applet to a particular web page.
    I really like SpinyNorman's JavaScript, but if that's indeed your purpose, you might as well do it in the Applet itself. In other words, it's kind of pointless to ask for a password in order to launch the Applet - once the user gets the Applet's URL by some means, he can just bypass the JavaScript authentication.

  • How to pass values from main window to pop-up window?

    I want to pass a value from the main window (1st form) to pop-up window (2nd form). The first form is of name booking.jsp and 2nd form is of name Fund_booking.jsp. I am using window.showModalDialog to open the window. I think, I have written right code in main window to pass the value but even then I am not able to get it on pop-up window. I am not even able to display an alert on pop-up window saying "hi" by writing a function on save Button in pop-up window. The code is as follows:
    On booking.jsp:
    <script>
    function popup()
    var aForm;
    aForm = D_requisition_id.options[D_requisition_id.selectedIndex].text;
    \\Here I have captured value from a drop down box in my main window form and assigned it to the variable.
    alert(aForm);
    var myObject =new Object();
    myObject.Brandcode = aForm;
    alert(myObject.Brandcode);
    window.showModalDialog("Fund_booking.jsp",myObject,"dialogHeight:400px;dialogWidth:420px;");
    </script>
    <button name="B_FundBooking" tabIndex=4 style='POSITION:absolute;LEFT:393;TOP:292;WIDTH:100;height:24;BACKGROUND-COLOR:buttonface' onClick ="popup()">Fund Booking</button>
    On Fund_booking.jsp:
    <SCRIPT>
    var oMyObject = window.dialogArguments;
    var sBrandcode = oMyObject.Brandcode;
    alert(sBrandcode);
    </SCRIPT>
    Even the following alert is not getting displayed in pop-up window;
    <script>
    function ValidateData()
    alert("Hi");
    </script>
    <button name="B_Save" tabIndex=1 style='POSITION:absolute;LEFT:255;TOP:315;WIDTH:75;height:24;BACKGROUND-COLOR:buttonface' onClick ="ValidateData()">Save</button>
    I am using DIV instead of frames in my both forms. I just want to get that value in my pop-up window to write a query based on which data will get displayed in my table of pop-up window.
    Plz help me to solve this problem.

    Well, this is actually a JavaScript question, not a Java question but I can give some hints.
    When you do pop-up windows you need to put JavaScript in the html of the pop-up itself. Data can be passed by creating new fields in the window object, which the popup can access via the window.openner field.
    So, before invoking the popup add any data to be passed to the window object, then the onLoad function in the popup grabs the data.

  • How to pass value from report to form?

    Dear,
    I built a report and I create button on report too. This
    button will show a form that I want it to automatically show
    receivable values from report so that user don't complete them.
    So I create a button on the report . I enter Javascript in
    PL/SQL Code tab in '...after displaying the footer' as follow :
    htp.formOpen
    (owa_util.get_owa_service_path||'portal30.wwa_app_module.link?
    p_arg_names=_moduleid&p_arg_values=1736929105&p_arg_names=_show_h
    eader&p_arg_values=YES&p_arg_names=GNO&p_arg_values=1&p_arg_names
    =QNO&p_arg_values=2');
    htp.formSubmit(null,'New Answer');
    htp.formClose;
    GNO , QNO is value which I want to pass
    As you can see, the above code can pass only static value.
    But I want to pass values that is the condition of this report.
    I mean,such as, this report show data that gno=1 and qno=2 and I
    want to pass these values to form. So both value will appear in
    gno and qno field.
    So please tell me what should I do. Please help me. I don't
    know how to do it. I look forward to hearing from all of you.
    Please!!!!!! Don't hesitate to answer.
                        Thank you very much
                   Sirin Kittichotpanich

    Hi Marc,
    Yes, you have it correct in what I am trying to do and if I put a default value in the hidden item on page 2 and run it then that works fine. I just can't get the value from the form passed to page 2 for some reason. There are actually 22 items on the form that can be filtered but just using COREID for simplicity. When I run the form I am just entering a value in the COREID field to try and return those records. Most of the other items on the form are displayed as Popup LOV(fetches first row). Would the values of all these be done the same in a comma delimited list for the items and values? I was trying to get at least one of them working first. Here is the search result that comes up in the debug window:
    Search Results
    0.01: Item: P2_COREID HIDDEN
    0.01: show report
    0.02: determine column headings
    0.02: parse query as: MOTEAMSAPEX
    0.02: binding: ":P2_COREID"="P2_COREID" value=""
    0.02: print column headings
    0.02: rows loop: 15 row(s)
    No data found.
    Here is the SQL statement:
    select coreid, serialnumber
    from MOTEAMS.V_ASSETS where
    instr(UPPER("COREID"), UPPER(:P2_COREID)) > 0
    The branch settings are:
    Set these items: P2_COREID
    With these values: &P1_COREID (also tried this with period at the end)
    I am new to this and not familiar with apex.oracle.com. How would I go about posting to that site?
    Thanks,
    Pam

  • How to pass value from main window to pop up window?

    I want to pass a value from the main window (1st form) to pop-up window (2nd form). The first form is of name booking.jsp and 2nd form is of name Fund_booking.jsp. I am using window.showModalDialog to open the window. I think, I have written right code in main window to pass the value but even then I am not able to get it on pop-up window. I am not even able to display an alert on pop-up window saying "hi" by writing a function on save Button in pop-up window. The code is as follows:
    On booking.jsp:
    <script>
    function popup()
    var aForm;
    aForm = D_requisition_id.options[D_requisition_id.selectedIndex].text;
    \\Here I have captured value from a drop down box in my main window form and assigned it to the variable.
    alert(aForm);
    var myObject =new Object();
    myObject.Brandcode = aForm;
    alert(myObject.Brandcode);
    window.showModalDialog("Fund_booking.jsp",myObject,"dialogHeight:400px;dialogWidth:420px;");
    </script>
    <button name="B_FundBooking" tabIndex=4 style='POSITION:absolute;LEFT:393;TOP:292;WIDTH:100;height:24;BACKGROUND-COLOR:buttonface' onClick ="popup()">Fund Booking</button>
    On Fund_booking.jsp:
    <SCRIPT>
    var oMyObject = window.dialogArguments;
    var sBrandcode = oMyObject.Brandcode;
    alert(sBrandcode);
    </SCRIPT>
    Even the following alert is not getting displayed in pop-up window;
    <script>
    function ValidateData()
    alert("Hi");
    </script>
    <button name="B_Save" tabIndex=1 style='POSITION:absolute;LEFT:255;TOP:315;WIDTH:75;height:24;BACKGROUND-COLOR:buttonface' onClick ="ValidateData()">Save</button>
    I am using DIV instead of frames in my both forms. I just want to get that value in my pop-up window to write a query based on which data will get displayed in my table of pop-up window.
    Plz help me to solve this problem.

    just attach the value with its url for example
    String names="java";
    <a href="# onclick="window.open('file.jsp?name='+names);"></a>

  • Passing value from JSP to JSPDynPage onclick of link

    Hi,
    I have extracted a value in the JSP page and i want to send this value back to the JSPDynPage on click of a link(the link is dependent on the value).
    How can i do that?

    hi Sujoy,
    you can pass values by using beans and display the passed data in a new jsp page.
    firstly create a jsp page,that accepts user data,say for example i am placing a text box and a button,
    next,create a jspdyn page---
    private final static int INITIAL_STATE = 0;
        private final static int FINAL_STATE = 1;
        private int state = INITIAL_STATE;
        private final static String BEAN_KEY="nameBean";
        public void doInitialization(){
          IPortalComponentRequest request=(IPortalComponentRequest) this.getRequest();
          IPortalComponentContext ctxt=request.getComponentContext();
          displayNameBean mybean = new displayNameBean();
          ctxt.putValue(BEAN_KEY,mybean);
    public void doProcessAfterInput() throws PageException {
             InputField myInputField = (InputField) getComponentByName("user_name");
    if (myInputField != null) {
    IPortalComponentRequest request=(IPortalComponentRequest) this.getRequest();
    IPortalComponentContext ctxt = request.getComponentContext();
                 displayNameBean mybean1=(displayNameBean)ctxt.getValue(BEAN_KEY);
                   mybean1.setName(myInputField.getValueAsDataType().toString());
        public void doProcessBeforeOutput() throws PageException {
          switch (state){
               case INITIAL_STATE:
               this.setJspName("loginPage.jsp");
               break;
               case FINAL_STATE:
               this.setJspName("successloginPage.jsp");
               break;
        public void onButtonClick(Event event) throws PageException {
             state=FINAL_STATE;       
    finally display this value in a new jsp page as follows--
    <jsp:useBean id="nameBean" scope="application" class="NewProject.bean.displayNameBean" />
    <%@ taglib uri= "tagLib" prefix= "hbj"%>
    <hbj:content id="myContext" >
      <hbj:page title="PageTitle">
       <hbj:form id="myFormId" >
    <hbj:textView
         id="welcome_note"
         design="HEADER2">
         <% 
         welcome_note.setText
         (nameBean.getName());
         %>
    as simple as that!!
    regards
    SwarnaDeepika
    P.S:Please reward points for helpful answers.

  • How to pass values from one section to another section in same dashboard..

    hi
    I am in need of designing a dashboard which contains 2 sections.In first section i will include a Dashboard prompt and in the second section, I have to display a jsp page by passing the result of prompt as a parameter.
    how to pass these values.....
    if possible send me some links regarding this
    thanks in advance...............

    Check my blog entry here http://oraclebizint.wordpress.com/2007/12/26/oracle-bi-ee-101332-drills-across-sections-in-a-dashboard/. It has an example.
    Thanks,
    Venkat
    http://oraclebizint.wordpress.com

  • ESB  : How to Pass value from one RS to another RS

    Hi Gurus,
    I want to pass a value from one First Routing service to another to set the value for the last XSL transformation.
    How can I do this without creating specific XSDs??
    Rgs
    JO

    Data flowing through the ESB is XML-based (or opaque), so if the value you want to pass is in the XML result of RS1, you can use it in RS2. If you have a good reason why not too or this doesn't work for you, you could store data somewhere along the ESB process (database, stateful bean, etc.). Otherwise, you would need to let the ESB generate (or create you own) XSD describing the XML.
    Regards,
    Ronald

  • How to pass values from single Databank file across different scripts?

    Hi Guys,
    I have a question regarding using single databank file across different scripts.
    Lets say there 5 web service scripts and these are very generic scripts where the input/request xml schema of each script is parameterized without having any databank as script asset.
    These 5 web service scripts are like library functions and so we dont want to attach any databank as script asset.
    However I have a driver script to call all of these 5 library scripts and now I attach a databank (a .csv file) to the driver script as script asset. Say this .csv file has got 10 different columns with just single record/row.
    As and when the function call goes to those 5 scripts i.e one by one, then based on the function call the corresponding columns are used and the data for those columns must be read.
    Is there any solution to acheive this?
    Faster help is highly appreciated.

    Hi JB,
    what i was looking for, was an approach to use a databank file (.csv file) in a parent script and then by reading that .csv file, the data should be moved from the parent script to individual child scripts.
    The child scripts are very generic scripts and are like library functions which are not data dependent. they are fully parameterized and they dont have any sort of databank attached to them.
    Now the question is if the databank has got 10 columns where first 3 columns belong to one child script, second 3 columns belong to 2nd child script and so on.
    Then how do we pass the values from parent script to a child script and what is the best/recommended approach.

Maybe you are looking for

  • Reg: Billing document not released to Accounting -Error

    Hi Gurus, I am facing a problem in Billing.I am creating a billing document and while saving the document it shows up the error " Credit Control area 1200 not assigned to Company Code 1000". I have checked the enterprise structure and everything rega

  • Hyperlinks not working in PDF created from Word

    I have created a Word document containing hyperlinks but when I print it to a PDF file (using Acrobat 7.0.9 on Windows Server 2003), the hyperlinks look OK in the PDF file but nothing happens when I click on them. In Acrobat, under Edit > Preferences

  • IPhone Unlocking ( No Service )

    Hello, I Bought an Iphone from about one year .. and it was factory unlocked i kuwait after upgrading to 5.1.1 and baseband upgaraded to 4.12.01 now it's locked and giving me an error message ( No Service ) please help i can't use my phone anymore

  • Close a course

    I would like to be able to close a course on a button click but 'Close Course' is not an action option. Does anybody have any ideas. I know they could click the red 'x' to close the window but I would also like to put it behind a 'Close' button. Thx.

  • Value category customizing - ps

    hi ps experts, pl help in let me know how to customise value category in ps. thanx & regards Srihari