Java Relay Servlet Help

maduprasad

Active member
  • Sep 13, 2006
    926
    149
    43
    machan mata me case eka poddak karana hati kiyala denawada

    a) The first page will be a login page for the contestant and the administrator. Password for their accounts should be stored in the database and checked on login - if correct, the person is presented with a main menu, if not then a suitable error message will be displayed.
    b) Only the administrators should be able to view all the information in the database stored about a quiz e.g. all the question texts, all the answer texts, and all the correct answers. You should provide a quiz topic. You may make up the questions and answers.
    c) A contestant should be able to start a quiz, answer n questions and get the results.
     

    kushame

    Junior member
  • Aug 18, 2010
    284
    12
    18
    kara ma dekaka tiyenaw
    1 java wala api ake kotasak tiyenawa e magin karanna puluwan
    2 apita database ake dala ati code gahala karanna puluwan
     

    heenputha

    Well-known member
  • Oct 15, 2010
    1,226
    197
    63
    Here is the simple login form..

    This code goes with index.jsp. YOur jsp page

    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>JSP Page</title>
    </head>
    <body>
    <h2>Hello World!</h2>
    <form action="Login">
    <input type="text" name="name"/>
    <input type="password" name="pass"/>
    <input type="submit" value="Login"/>

    </form>
    </body>
    </html>


    This is the login.java class. Your loging servlet

    package src;

    import java.io.*;
    import java.sql.Connection;
    import java.sql.ResultSet;
    import java.sql.Statement;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class Login extends HttpServlet {
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    PrintWriter out = response.getWriter();
    String s=request.getParameter("name");
    String s1=request.getParameter("pass");

    try {

    Connection conn = Md.DB.connect();
    Statement stmt=conn.createStatement();
    ResultSet rs=stmt.executeQuery("select * from log where User='"+s+"' and pass='"+s1+"'");
    if(rs.next()){
    out.print("Hello");
    }else{
    out.print("Error");
    }


    } catch (Exception ex) {

    }



    }


    }


    You must create your data base connectivity in a separate class and make an object of it to call it in the loging servlet. Hope you have an idea about simple JDBC. If u need more info pls PM me. I'll send you the code for sessioning.