Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Jul 2008
    Posts
    57
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Javascript vs JSP

    Hi,

    i have the javascript and jsp combination code for calendar functionality is there.

    in that i take the events from database.For that i write a condition to select the events as "select * fom importtimetable where month='jspvar'. This statement didn't work. In that i declared jspvar as
    <script>var jsvar=monthNum;</script>
    String jspvar="<script>document.writeln("javar")</script>";

    Now jspvar didn't pass to the select statement. Anybody plz tell that whats the wrong in that

    [javascript]

    function createCalendar(monthNum,yearNum) {
    calendarString = '';
    var daycounter = 0;

    calendarString +='<td height=\"20\" colspan=\"4\" valign=\"top\"><a class=\"breadlink\" href=\"#\">Home</a> - Calender of Events</td>';
    calendarString +='<td width=\"21%\" height=\"30\"><font class=\"calender\">'+ wordMonth[monthNum-1]+ todaysDate +'</font></td>';

    calendarString +='<option selected>'+ wordMonth[monthNum-1]+'</option>';
    calendarString +='<option value=1>January</option>';
    calendarString +='<option value=2>February</option>';
    calendarString +='<option value=3>March</option>';
    calendarString +='<option value=4>April</option>';
    calendarString +='<option value=5>May</option>';
    calendarString +='<option value=6>June</option>';
    calendarString +='<option value=7>July</option>';
    calendarString +='<option value=8>August</option>';
    calendarString +='<option value=9>September</option>';
    calendarString +='<option value=10>October</option>';
    calendarString +='<option value=11>November</option>';
    calendarString +='<option value=12>December</option>';
    calendarString +='</select>';
    calendarString +='<select name="select5">';
    calendarString +='<option>21-24</option>';
    calendarString +='</select>';
    calendarString +='<select name=\"select4\" id=\"select4\" onchange=\"selectdate()\">';
    calendarString +='<option selected>'+ yearNum +'</option>';
    calendarString +='<option value=2006>2005</option>';
    calendarString +='<option value=2007>2006</option>';
    calendarString +='<option value=2008>2007</option>';
    calendarString +='<option value=2009>2008</option>';
    calendarString +='<option value=2010>2009</option>';
    calendarString +='<option value=2011>2010</option>';
    calendarString +='<option value=2012>2011</option>';
    calendarString +='<option value=2013>2012</option>';
    calendarString +='<option value=2014>2013</option>';
    calendarString +='<option value=2015>2014</option>';
    calendarString +='<option value=2016>2015</option>';
    calendarString +='<option value=2017>2016</option>';
    calendarString +='</select>';
    var jsvar=monthNum;
    <%@ page language="java" %>
    <%
    String connectionURL = "jdbc:mysql://localhost:3306/";
    String dbName = "user_register";
    Connection connection = null;
    Statement stmt = null;
    ResultSet rs = null;
    ResultSet rs2 = null;
    PreparedStatement pstatement = null;
    PreparedStatement pstatement2 = null;
    String title = request.getParameter("title");
    String description = request.getParameter("description");
    String month = request.getParameter("month");
    String jspvar="<script>document.writeln(jsvar)</script>";
    Class.forName("com.mysql.jdbc.Driver").newInstance();
    connection = DriverManager.getConnection(connectionURL+dbName, "root", "root");
    pstatement2 = connection.prepareStatement("Select * from importtimetable where month='jspvar'");
    rs2 = pstatement2.executeQuery();
    while(rs2.next()){
    %>

    calendarString +='<td width=\"66\" height=\"66\" align=\"center\" bgcolor=\"#EBFEE0\" class=\"text\">00:00</td>';
    calendarString +='<td width=\"638\" height=\"55\" align=\"left\" valign=\"top\" bgcolor=\"#FFFFFF\"><%=rs2.getString(1)%>&nbsp;</td>';
    <%
    }
    %>
    }


    [/javascript]

  • #2
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    where is php here?

    Edit: thread was moved to jsp forum. Now the problem is:

    why I'm asking op about php in jsp forum,

    regards
    Last edited by oesxyl; 11-28-2008 at 07:35 AM.

  • #3
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Please note that this is the PHP forum, not the java forum.

    Anyway, its because you're jspvar inside you're select is wrapped and treated as a string value, not as a variable.
    Code:
    pstatement2 = connection.prepareStatement("Select * from importtimetable where month='" + jspvar + "'");
    On the other hand, month will equal the string '<script>document.writeln(jsvar)</script>', not the intended value.
    Javascript is not capable of interacting with any server side language, including java. You'll need to use ajax in order to do this.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 


  •  

    Posting Permissions

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