Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

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


Ïà¹ØÎĵµ£º

jsp½¨Õ¾Àú³Ì

      Á½ÄêÇ°£¬ÔøÓÐһλǰ±²¶ÔÎÒ˵¹ý£º¿ª·¢Ò»¸öÊôÓÚÄã×Ô¼ºµÄÍøÕ¾£¬È»ºóÿÌ컨һµã¿ÕÏеÄʱ¼äÈ¥¾­ÓªÒ»Ï£¬ÖÕÓÐÒ»Ì죬Äã»á·¢¾õËüÊǷdz£ÓÐÓõġ£¸Õ¿ªÊ¼µÄʱºò£¬ÎÒûÓаÑÕâЩ»°·ÅÔÚÐÄÉÏ£¬ÂýÂýµØ£¬ÎҲŷ¢¾õÕâλǰ±²ËµµÄ»°ÊǺÜÓеÀÀíµÄ¡£¼ÙÉèÁ½ÄêÇ°¿ªÊ¼¾­ÓªÒ»¸öÍøÕ¾£¬Í¨¹ýÕâÁ½ÄêµÄÍƹãºÍÔËÓª£¬Ëµ²»¶¨µ½Ï ......

MyEclipseÖв»ÄÜÌáʾJSPÒ³ÃæµÄhtml±ê¼ÇÊôÐÔÖµ£¿

ÄãµÄ¿ì½Ý½¨ÉèÖÃÓÐÎÊÌ⣬ÄãÖØÐÂÉèÖÃÒ»ÏÂÔÚ window --> Perferences--> General--> keys
½«Content Assist¿ì½Ý¼üÉèÖóÉAlt + /¾Í¿ÉÒÔÁË
Èç¹ûÄã·¢ÏÖµãÁËApply¹ØÁËÖ®ºó£¬Ôٴδò¿ªContent AssistµÄ¿ì½Ý¼üûÓиıäµÄ»°£¬ÄÇÊÇÒòΪÏÂÃæÓÐÒ»¸öÑ¡ÏîÒѾ­Óõ½ÁËAlt + /£¬¾ßÌåÊÇÄÄÒ»¸öÎҼDz»ÇåÁË£¬Äã°ÑÄǸöcommandµÄ¿ì½Ý¼ü¸ ......

jsp¶ÁÈ¡Êý¾Ý¿âÖÐÎÄÂÒÂëÎÊÌâ

Õâ¸öÎÊÌâÊÇ´ÓÏîÄ¿ÖÐÉè¼ÆÊý¾Ý¿âºÍ²Ù×÷Êý¾Ý¿âµÄÈ˲»Í¬¶øÔì³ÉµÄ¡£ËùÓõÄÊý¾Ý¿â
ÊÇsybase£¬Éè¼Æʱ°ÑÊý¾ÝÀàÐÍÉè¼ÆΪnvarcharÁË£¬Èç¹ûÊÇÖÐÎÄ£¬¶ÁÈ¡³öÀ´¾Í»áµÃ
µ½ÂÒÂë¡£ÎÒÊÔÁ˺ö෽·¨»¹ÊDz»ÐУ¬×îºóÎÞÄΣ¬Ö»ºÃ½«Êý¾ÝÀàÐ͸ÄΪvarcharÁË¡£
ËùÒÔÔÚ´Ë×ܽáÒ»ÏÂÖÐÎÄÂÒÂëÎÊÌâ¡£
Ò»¡¢JSPÓëÒ³Ãæ²ÎÊýÖ®¼äµÄÂÒÂë
   &nb ......

JSPÒ³ÃæÌøת´óÈ«

JSPÒ³ÃæÌøת´óÈ«
JSPÖеÄÌøת£º
(1). forward()·½·¨
    ʹÓõ½javax.servlet.RequestDispatcherÀà
    RequestDispatcher rd = getServletContext().getRequestDispatcher("url");
    rd.forward(requestVar,requestVar); //´«µÝservletµÄÈë¿Ú²ÎÊý
   ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ