jsp—MySqlÖÆ×÷B/sµÇ½µÄºÃÀý×Ó Ñ§Ï°±Ê¼Ç
½¨Á¢Ìõ¼þÊ×ÏÈÒ»¶¨ÒªÈ·¶¨×Ô¼ºµÄmysql£¬tomcat,eclipseÁ¬½ÓÊÇÕýÈ·µÄ¡£
index.jspºÜ¼òµ¥£¬¾ÍÒ»¸öÌøת¡£
<%
response.sendRedirect("lg.jsp");
%>
lg.jsp ʵÏֵǼ¿ò¼Ü
<%@ page contentType="text/html; charset=utf-8" %>
<html>
<head>
<title>
login
</title>
</head>
<center>
Prease input UserName and Pssword!!
</center>
<body bgcolor="#ffffff">
<%String flag=request.getParameter("flag");
if(flag!=null&&flag.equals("0")){
out.println("Pls input valid username and password!<br><br>");
}
%>
<form name="form1" method="post" action="login.jsp">
<center>
<input name="UserName" type="text" ><br/>
<input name="Password" type="password"><br/>
<input name="submit" type="submit" value="submit">
<input name="reset" type="reset" value="reset">
</center>
</form>
</body>
</html>
login.jsp Îļþ
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.sql.*"%>
<html>
<head>
<title>Óû§µÇ½</title>
</head>
<body>
<%
String UserName=request.getParameter("UserName");
String Password=request.getParameter("Password");
ResultSet rs=null;
Statement stmt=null;
Connection con=null;
boolean flag=false;
try{
//Çý¶¯³ÌÐòÃû
String driverName="com.mysql.jdbc.Driver";
//Êý¾Ý¿âÓû§Ãû
String userName="test";
//ÃÜÂë
String userPasswd="123456";
//Êý¾Ý¿âÃû
String dbName="along";
//±íÃû
String tableName="user";
String url="jdbc:mysql://localhost/"+dbName+"?user="+userName+"&password="+userPasswd;
Class.forName("com.mysql.jdbc.Driver").newInstance();
con=DriverManager.getConnection(url);
stmt = con.createStatement();
String sql="select * from user where UserName='"+UserName+"' and Password='"+Password+"'";
System.out.println("login: "+sql);
rs = stmt.executeQuery(sql);
//System.out.printl
Ïà¹ØÎĵµ£º
ÔÚÎÒÃÇ×°ºÃMyEclipseʱ,ÓÐʱ˫»÷´ò¿ªjspÒ³Ãæ,
»áÌáʾ´íÎó,ÎÞ·¨ÏÔʾҳÃæ.
Òò´ËÒª½«jspµÄĬÈÏ´ò¿ª·½Ê½¸Ä³É´úÂëÊÔͼ£º
°ì·¨:Ôڲ˵¥À¸µÄ
1.window—->perferences—–>General——->editors——>file associations
2.Ñ¡Ôñjsp——->Ñ¡ÔñÏàÓ¦µÄeditor¡¡Îªdef ......
<body style="height:100%;">
-------------------------------------------------------------------Ò»¿ªÊ¼µÄÒ³Ãæ----------------------
fdasfsdfadf
<input name="button2" onclick="ShopConfirm('fdsaf')" value="µãÎÒ" type="button"/>
--------------------------------------------------------- ......
1¡¢Óû§µÇ¼½çÃælog.jsp
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content ......
Äãʱ³£±»¿Í»§±§Ô¹JSPÒ³ÃæÏìÓ¦ËٶȺÜÂýÂð£¿ÄãÏë¹ýµ±¿Í»§·ÃÎÊ´ÎÊý¾çÔöʱ£¬ÄãµÄWEBÓ¦ÓÃÄܳÐÊÜÈÕÒæÔö¼ÓµÄ·ÃÎÊÁ¿Âð£¿
±¾ÎĽ²ÊöÁ˵÷ÕûJSPºÍservletµÄһЩ·Ç³£ÊµÓõķ½·¨£¬Ëü¿ÉʹÄãµÄservletºÍJSPÒ³ÃæÏìÓ¦¸ü¿ì£¬À©Õ¹ÐÔ¸üÇ¿¡£¶øÇÒÔÚÓû§ÊýÔö¼ÓµÄÇé¿öÏ£¬ÏµÍ³¸ºÔØ»á³ÊÏÖ³öƽ»¬Éϳ¤µÄÇ÷ÊÆ¡£ÔÚ±¾ÎÄÖ ......