|
|
| java+jsp |
Expert:ajith
I want to know how can I use java class in my jsp page?i'm not gettin hw it is.please help me.if u can give me the explanation with one example its good for me..
thanks in advance ajith.. |
| Answers |
Hi friend,
<%@ page language="java" %> Please enter your Name and Password here: <br> <br> <form name="frm" action="/JSPMultipleForms/Authentication" method="Post" > Name: <input type="text" name="user" value=""/> Password:<input type="text" name="pass" value=""/> <input type="submit" value="Check" /> </form>
---------------------------------
java file
import java.io.*; import java.util.*; import java.sql.*; import javax.servlet.*; import javax.servlet.http.*;
public class Authentication extends HttpServlet{
private ServletConfig config; public void init(ServletConfig config) throws ServletException{ this.config=config; } public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException,IOException{ PrintWriter out = response.getWriter(); String connectionURL = "jdbc:mysql://192.168.10.59/messagepaging"; Connection connection=null; ResultSet rs; String userName=new String(""); String passwrd=new String(""); response.setContentType("text/html"); try { // Load the database driver Class.forName("com.mysql.jdbc.Driver"); // Get a Connection to the database connection = DriverManager.getConnection(connectionURL, "root", "root"); //Add the data into the database String sql = "select user,password from User"; Statement s = connection.createStatement(); s.executeQuery (sql); rs = s.getResultSet(); while (rs.next ()){ userName=rs.getString("user"); passwrd=rs.getString("password"); } rs.close (); s.close (); }catch(Exception e){ System.out.println("Exception is ;"+e); } if(userName.equals(request.getParameter("user")) && passwrd.equals(request.getParameter("pass"))){ out.println("User Authenticated"); } else{ out.println("You are not an authentic person"); } } } -------------------------------------------------------
Read for more information.
http://www.roseindia.net/jsp/
Thanks
|
| More Questions |
|
|
Post Answers
Ask Question
Facing Programming Problem?
|
|
|
|
|