Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: To call java method in jsp

  1. #1
    Junior Member
    Join Date
    Apr 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile To call java method in jsp

    Hi All,

    I am trying to call a java method in jsp. The main idea is to hide menu based on the user who logs in. Please go through the code and provide me a solution guys.



    The java class flows like this,
    public class UserVerification {

    public static void main(String[] args) {
    UserVerification obj = new UserVerification();
    System.out.print(obj.GetUserVerification("abc"));
    }

    public int GetUserVerification(String empID) {
    int roleId = 0;
    try {

    Class.forName("com.microsoft.sqlserver.jdbc.SQLSer verDriver");

    Connection connection = DriverManager.getConnection("");

    PreparedStatement ps = connection.prepareStatement("");
    ResultSet resultSet = ps.executeQuery();
    while (resultSet.next()) {
    roleId = Integer.parseInt(resultSet.getString(""));
    int RoleID = 0;
    UserMaster um = new UserMaster();
    um.getRoleID();

    while ((RoleID == roleId) && resultSet.next()) {
    UserInfoDisplayController ui = new UserInfoDisplayController();
    List<UserMaster> objUser = ui.GetUserInfoDisplayController(1);
    System.out.print(objUser.size());
    for (UserMaster um1 : objUser) {
    um1.getEmpID();
    um1.getUserName();
    um1.getEmailID();
    um1.getRoleID();
    um1.getSupervisor();
    um1.getTeamID();
    }
    }
    }
    ps.close();
    ps.close();
    connection.close();

    } catch (Exception e) {
    e.printStackTrace();
    }
    return roleId;
    }
    }



    And the javascript and jsp in which i call this are shown below,



    <script type="text/javascript">
    function Validation(RoleID) {
    alert("one");
    var el = document.getElementById(cssmenu);
    alert("two");
    if (RoleID != 2) {
    el.style.visibility == "visible";
    } else {
    el.style.visibility == "hidden";
    }
    alert("three");
    }
    alert("four");
    </script>



    <div id='cssmenu'>
    <ul>
    <%
    if (RoleID != 2) {
    %>
    <li id="menu"><a href="UserMaster.jsp" >User Master</a></li>
    <li id="menu"><a href="SkillMaster.jsp" >Skill Master</a></li>
    <li id="menu"><a href="SkillMapping.jsp" >Skill Mapping</a></li>
    <li id="menu"><a href="Report.jsp" >Reports</a></li>
    <%
    }
    %>
    <li><a href="MySkills.jsp" >My Skills</a></li>
    </ul>
    </div>


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: To call java method in jsp

    Please go through the code and provide me a solution guys.
    That isn't really how this works. First off, use the highlight tags to preserve formatting when posting code. Secondly. what does this code do? What about your problem are you stuck on?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. How to call Servlet from JSP Along with a parameter
    By Shivputra in forum JavaServer Pages: JSP & JSTL
    Replies: 2
    Last Post: March 6th, 2014, 12:12 PM
  2. not able to call java method from setonchange() event
    By shailesh in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 4th, 2014, 07:33 AM
  3. [Help] How can I call a servet from jsp
    By vdupham in forum Java Servlet
    Replies: 2
    Last Post: May 16th, 2013, 06:22 PM
  4. Can i call init() method in destroy method.?
    By muralidhar in forum Java Servlet
    Replies: 1
    Last Post: October 22nd, 2010, 11:18 AM
  5. JSP freezes after AJAX call !!
    By java_freek in forum JavaServer Pages: JSP & JSTL
    Replies: 1
    Last Post: April 16th, 2010, 10:31 AM