Results 1 to 6 of 6
  1. #1
    newto is offline Member
    Join Date
    May 2010
    Posts
    17
    Rep Power
    0

    Default navigating between jsp

    Hi,
    I am creating a web application. In that I have multiple radio button and two button.
    What I want to do is--
    I want to choose a radio button and according to that value if I will click the button1, I want to display a different jsp page.
    But I don't know how to do that, because I am using a form in the jsp page and i set the type property for the from as type="newjsp.jsp". It displaying me the newjsp, when i click that button
    But how can I work with the next button, if I want to display some different jsp page after clicking that button

    I want to do something like this.

    If radiobut1.checked then

    at click of button1

    display jspnew.jsp

    else

    if radio2.checked then

    at click of button1

    display jspuse.jsp.

    end if

    and

    button2.click

    jsptest.jsp

    .

    I have write by all the methods in javabeans, what I want is to use that method value on jsp.
    and also want to send some value from jsp page to the class, to fetching data from database, using as parameter for the query(testbox)

    Please can any one suggest me what way i should go.

    Thank you in advance

  2. #2
    Sno's Avatar
    Sno
    Sno is offline Senior Member
    Join Date
    Apr 2010
    Posts
    196
    Rep Power
    5

    Default

    1. Javascript is very different from java.
    2. I would suggest coding in javascript(js), and just linking your jsp to your js,
    Java Code:
    <script type="text/javascript" src="FORM.js"></script>
    3. You can google your answer. Look for button event handlers or actions
    4. use a functions.
    :rolleyes: ~ Sno ~ :rolleyes:
    '-~ B.S. Computer Science ~-'

  3. #3
    monika is offline Member
    Join Date
    Mar 2010
    Posts
    15
    Rep Power
    0

    Default How to integrate jsp with java script file

    Thank you for your reply.
    I am creating a simple web application in which I am calling a javascript funtion

    If I write the javascript function in the jsp page like this it work fine


    <%@page contentType="text/html" pageEncoding="UTF-8"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

    <html>

    <font color="blue">Please Enter User Name and Password </font><br><br>

    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>Implementing css and javascript</title>

    <link rel="stylesheet" type="text/css" href="style.css">

    <script type="text/JavaScript" >
    function validate(theForm){
    if(theForm.user.value.length==0){
    alert("UserId can't be blank");
    theForm.user.focus();
    return false;
    }else if(theForm.pass.value.length==0){
    alert("Password can't be blank");
    theForm.pass.focus();
    return false;
    }else if(theForm.pass.value.length<6){
    alert("Password length can't be less than 6 char");
    theForm.pass.focus();
    return false;
    }
    }
    </script>

    </head>
    <body>
    <form enctype="multipart/form-data" onSubmit="return validate(this)" method="post" action=Welcome.html>
    <%--action="Welcome.html>--%>
    <table border = "0">
    <tr align="left" valign="top">
    <td>User Name:</td>
    <td><input type="text" name ="user" class="inputbox"/></td>
    </tr>
    <tr align="left" valign="top">
    <td>Password:</td>
    <td><input type="password" name ="pass" class="inputbox"/></td>
    </tr>
    <tr align="left" valign="top">
    <td></td>
    <td><input type="submit" name="submit"
    value="submit" class="submitButton"/>

    </td>
    </tr>
    </table>
    </form>

    </body>
    </html>


    But I made seperate file named newjs.js in the project and try to call it in the jsp it didnt work


    validate.js

    function validate(theForm){
    if(theForm.user.value.length==0){
    alert("UserId can't be blank");
    theForm.user.focus();
    return false;
    }else if(theForm.pass.value.length==0){
    alert("Password can't be blank");
    theForm.pass.focus();
    return false;
    }else if(theForm.pass.value.length<6){
    alert("Password length can't be less than 6 char");
    theForm.pass.focus();
    return false;
    }
    }

    index.jsp


    <%@page contentType="text/html" pageEncoding="UTF-8"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

    <html>

    <font color="blue">Please Enter User Name and Password </font><br><br>

    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>Implementing css and javascript</title>

    <link rel="stylesheet" type="text/css" href="style.css">

    <<script language="JavaScript" type="text/JavaScript" src="../script/validate.js"></script>

    </head>
    <body>
    <form enctype="multipart/form-data" onSubmit="returnvalidate(this)" method="post" action=Welcome.html>
    <%--action="Welcome.html>--%>
    <table border = "0">
    <tr align="left" valign="top">
    <td>User Name:</td>
    <td><input type="text" name ="user" class="inputbox"/></td>
    </tr>
    <tr align="left" valign="top">
    <td>Password:</td>
    <td><input type="password" name ="pass" class="inputbox"/></td>
    </tr>
    <tr align="left" valign="top">
    <td></td>
    <td><input type="submit" name="submit"
    value="submit" class="submitButton"/>

    </td>
    </tr>
    </table>
    </form>

    </body>
    </html>


    I have save the js file in the same folder the jsp file is present

    like
    web-INF(folder)
    index.jsp
    validate.js
    welcome.html
    style.css

    Can you please tell me how to intregate the js file in jsp

  4. #4
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    Why did you put that path in the JSP for the src of the Javascript? Is the javascript file in a folder called script or did you just gess the path to use?

    IF the script is in a folder called script then use the path
    src="${pageContext.request.contextPath}/script/validate.js"

  5. #5
    dswastik is offline Senior Member
    Join Date
    Dec 2008
    Location
    Kolkata
    Posts
    282
    Rep Power
    6

    Default

    I have save the js file in the same folder the jsp file is present
    but the path says

    Java Code:
    src="../script/validate.js"
    so probably it should be src="validate.js"
    Swastik

  6. #6
    monika is offline Member
    Join Date
    Mar 2010
    Posts
    15
    Rep Power
    0

    Default

    Thank you for your reply.

    I have change the path for the js file.
    now its working

Similar Threads

  1. Creating and Navigating a 2D Array from .dat file
    By RobertF in forum New To Java
    Replies: 0
    Last Post: 03-10-2009, 06:44 PM
  2. Blank Screen while navigating from one screen to another
    By mohana.krishna in forum Java Servlet
    Replies: 0
    Last Post: 03-03-2009, 06:03 PM
  3. Navigating a URL
    By Paul77 in forum New To Java
    Replies: 0
    Last Post: 11-16-2008, 10:01 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •