導航:首頁 > 源碼編譯 > jsp登陸界面源碼

jsp登陸界面源碼

發布時間:2022-11-22 17:27:11

1. JSP登陸頁面小實驗

//20塊錢搞定...
<html>
<head>
<scriptsrc="......jquery.1.7.2.js"></script>
<scripttype="text/javascript">
varloginNum=0;
functionlogin(){
varac=$("input[name=account]").val();
varpwd=$("input[name=pwd]").val();
$.ajax({
url:"login.jsp",
type:"POST",
data:"name="+ac+"&pwd="+pwd,
success:function(res){
if(res==0){
loginNum++;
if(loginNum==3){window.close();}
}else{
window.location='login.jsp';
}
}
});
}
</script>
</head>
<body>
賬戶:<inputtype="text"name="account"/><br/>
密碼:<inputtype="password"name="pwd"/><br/>
<inputtype="button"value="登陸"onclick="login()"/>
</body>
</html>
login.jsp
<%
Stringac=request.getParameter("name");
Stringpwd=request.getParameter("pwd");
PrintWriterpw=response.getWriter();
Stringmsg="";
if(ac.equals("sa")&&pwd.equals("pwd")){
msg="1";
}else{
msg="0";
}
out.println(msg);
out.flush();
out.close();


%>
Welcome

2. 網上下的jsp源碼要怎麼用

需要部署到伺服器中

找到菜單window→ShowView→Servers,打開Servers視圖標簽,部署的Tomcat服務

在新打開的對話框中,有一個Project項,選擇要部署的項目

點擊「Finish」完成部署

這樣項目就部署到Tomcat裡面去了

3. idea 運行JSP後顯示源代碼是什麼情況

1.這種情況,應該是jsp的內容被當做文本直接顯示到了頁面上,一般在使用springMVC時可能出現這樣的問題,猜測可能使用了springMVC。
2.具體解決方案:
查找web.xml文件,並找到springMVC的相關配置

<servlet-mapping>
<servlet-name>springMVC</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>

將上面的內容改為下面的即可 攔截是/ 而不是/*
<servlet-mapping>
<servlet-name>springMVC</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>

原因:在這種情況向springMVC會把*.jsp,*.sql,*.txt都當做txt處理。結果就是直接在瀏覽器載入了jsp源碼。

4. jsp登陸界面源代碼

1、login.jsp文件

<%@ page language="java" contentType="text/html; charset=GB18030"

pageEncoding="GB18030"%>

<%@ page import="java.util.*" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

<head>

<title>登錄頁面</title>

</head>

<body>

<form name="loginForm" method="post" action="judgeUser.jsp">

<table>

<tr>

<td>用戶名:<input type="text" name="userName" id="userName"></td>

</tr>

<tr>

<td>密碼:<input type="password" name="password" id="password"></td>

</tr>

<tr>

<td><input type="submit" value="登錄" style="background-color:pink"> <input

type="reset" value="重置" style="background-color:red"></td>

</tr>

</table>

</form>

</body>

</html>

2、judge.jsp文件

<%@ page language="java" contentType="text/html; charset=GB18030"

pageEncoding="GB18030"%>

<%@ page import="java.util.*" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

<head>

<title>身份驗證</title>

</head>

<body>

<%

request.setCharacterEncoding("GB18030");

String name = request.getParameter("userName");

String password = request.getParameter("password");

if(name.equals("abc")&& password.equals("123")) {

3、afterLogin.jsp文件

%>

<jsp:forward page="afterLogin.jsp">

<jsp:param name="userName" value="<%=name%>"/>

</jsp:forward>

<%

}

else {

%>

<jsp:forward page="login.jsp"/>

<%

}

%>

</body>

</html>

<%@ page language="java" contentType="text/html; charset=GB18030"

pageEncoding="GB18030"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

<head>

<title>登錄成功</title>

</head>

<body>

<%

request.setCharacterEncoding("GB18030");

String name = request.getParameter("userName");

out.println("歡迎你:" + name);

%>

</body>

</html>

(4)jsp登陸界面源碼擴展閱讀:

java web登錄界面源代碼:

1、Data_uil.java文件

import java.sql.*;

public class Data_uil

{

public Connection getConnection()

{

try{

Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");

}catch(ClassNotFoundException e)

{

e.printStackTrace();

}

String user="***";

String password="***";

String url="jdbc:sqlserver://127.0.0.1:1433;DatabaseName=***";

Connection con=null;

try{

con=DriverManager.getConnection(url,user,password);

}catch(SQLException e)

{

e.printStackTrace();

}

return con;

}

public String selectPassword(String username)

{

Connection connection=getConnection();

String sql="select *from login where username=?";

PreparedStatement preparedStatement=null;

ResultSet result=null;

String password=null;

try{

preparedStatement=connection.prepareStatement(sql);

preparedStatement.setString(1,username);

result=preparedStatement.executeQuery();//可執行的 查詢

if(result.next())

password=result.getString("password");

}catch(SQLException e){

e.printStackTrace();

}finally

{

close(preparedStatement);

close(result);

close(connection);

}

System.out.println("找到的資料庫密碼為:"+password);

return password;

}

public void close (Connection con)

{

try{

if(con!=null)

{

con.close();

}

}catch(SQLException e)

{

e.printStackTrace();

}

}

public void close (PreparedStatement preparedStatement)

{

try{

if(preparedStatement!=null)

{

preparedStatement.close();

}

}catch(SQLException e)

{

e.printStackTrace();

}

}

public void close(ResultSet resultSet)

{

try{

if(resultSet!=null)

{

resultSet.close();

}

}catch(SQLException e)

{

e.printStackTrace();

}

}

}

2、login_check.jsp:文件

<%@ page language="java" contentType="text/html; charset=utf-8"

pageEncoding="utf-8"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<title>驗證用戶密碼</title>

</head>

<body>

<jsp:useBean id="util" class="util.Data_uil" scope="page" />

<%

String username=(String)request.getParameter("username");

String password=(String)request.getParameter("password");

if(username==null||"".equals(username))

{

out.print("<script language='javaScript'> alert('用戶名不能為空');</script>");

response.setHeader("refresh", "0;url=user_login.jsp");

}

else

{

System.out.println("輸入的用戶名:"+username);

String passwordInDataBase=util.selectPassword(username);

System.out.println("密碼:"+passwordInDataBase);

if(passwordInDataBase==null||"".equals(passwordInDataBase))

{

out.print("<script language='javaScript'> alert('用戶名不存在');</script>");

response.setHeader("refresh", "0;url=user_login.jsp");

}

else if(passwordInDataBase.equals(password))

{

out.print("<script language='javaScript'> alert('登錄成功');</script>");

response.setHeader("refresh", "0;url=loginSucces.jsp");

}

else

{

out.print("<script language='javaScript'> alert('密碼錯誤');</script>");

response.setHeader("refresh", "0;url=user_login.jsp");

}

}

%>

</body>

</html>

3、loginSucces.jsp文件

<%@ page language="java" contentType="text/html; charset=utf-8"

pageEncoding="utf-8"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

<title>Insert title here</title>

</head>

<body>

<hr size="10" width="26%" align="left" color="green">

<font size="6" color="red" >登錄成功 </font>

<hr size="10" width="26%" align="left" color="green">

</body>

</html>

4、user_login.jsp文件

<%@ page language="java" contentType="text/html; charset=utf-8"

pageEncoding="utf-8"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

<title>登錄界面</title>

</head>

<body background="C:Userswin8workspaceLoginimage\_10.jpg" >

<center>

<br><br><br><br><br><br>

<h1 style="color:yellow">Login</h1>

<br>

<form name="loginForm" action="login_check.jsp" method="post">

<table Border="0" >

<tr >

<td>賬號</td>

<td><input type="text" name="username"></td>

</tr>

<tr>

<td>密碼</td>

<td><input type="password" name="password">

</td>

</tr>

</table>

<br>

<input type="submit" value="登錄" style="color:#BC8F8F">

</form>

</center>

</body>

</html>

5. 用jsp怎樣做一個用戶登錄界面

//jsp文件,登錄界面
<%@pagepageEncoding="utf-8"contentType="text/html;charset=utf-8"%>
<body>
<h1>Register</h1>
<hr/>
<formaction="login"method="post">
用戶名:š
<inputtype="text"name="username"id="text"/>
密碼:š
<inputtype="password"name="pwd"id="text"//>
<inputtype="submit"value="登錄"id="button"/>
</form>
</body>
//這是server文件,web.xml部署名字login
importjava.io.IOException;

importjavax.servlet.ServletException;
importjavax.servlet.http.HttpServlet;
importjavax.servlet.http.HttpServletRequest;
importjavax.servlet.http.HttpServletResponse;
importjavax.servlet.http.HttpSession;

{

publicvoidservice(HttpServletRequestrequest,HttpServletResponseresponse)
throwsServletException,IOException{

response.setContentType("text/html;charset=utf-8");
request.setCharacterEncoding("utf-8");
Stringusername=request.getParameter("username");
Stringpwd=request.getParameter("pwd");

try{
if(username.equals("name")&&pwd.equals("pwd")){
system.out.print("登錄成功");
}else{
system.out.print("error");
}
}catch(Exceptione){
e.printStackTrace();
}
}
}

簡單的登錄界面,不需要資料庫,如果要鏈接資料庫就要判斷很多了

6. 給定JSP程序源碼如下:

a和d是表達式,所以有輸出;c和d是java程序片,要想輸出得用java的輸出,所以這里沒有輸出。
a是先加後輸出,d是先輸出後加,所以一個是2,一個是1.

7. jsp 中網站的首頁源代碼

這是最簡單的一個例子,資料庫要你自己建,用的是ACCESS

<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>JSP連接Access資料庫</title>
<style type="text/css">
<!--
.style1 {
font-size: 20px;
font-weight: bold;
}
-->
</style>
</head><body>
<div align="center" class="style1">JSP連接Access資料庫</div>
<br>
<hr>
<p><%
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); //載入驅動程序類別
Connection con = DriverManager.getConnection("jdbc:odbc:jspdata"); //建立資料庫鏈接,jspdata為ODBC數據源名稱
//建立Statement對象
Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
ResultSet rs = stmt.executeQuery("select * from lyb"); //建立ResultSet(結果集)對象,並執行SQL語句
%>
</p>
<p align="center">NUMB1數據表中記錄如下</p>
<table width="640" border="1" align="center" bordercolor="#7188e0">
<tr bgcolor="d1d1ff">
<th width="49">編號</th>
<th width="90">姓名</th>
<th width="126">E-mail</th>
<th width="221">網站</th>
<th width="80">QQ</th>
</tr>
<%
while(rs.next())
{
%>
<tr bgcolor="#f8f8f8">
<th><%= rs.getString(1) %></th>
<th><%= rs.getString(2) %></th>
<th><%= rs.getString(3) %></th>
<th bgcolor="#f6f6f8"><%= rs.getString(4) %></th>
<th><%= rs.getString(5) %></th>
</tr>
<%
}
rs.close();
stmt.close();
con.close();
%>
</table>
<p align="center"><br>
如果您能看到表格中的數據,說明連接資料庫成功!</p>
</body>
</html>

8. jsp登錄代碼

login.jsp

<%@ page language="java" pageEncoding="utf-8"%>
<html>
<head>

<title>登錄</title>
<script language="javascript">

function checkform() {
if (form4.name.value.length==0){
alert("請輸入正確的姓名!");
form4.name.focus();
return false;
}
if (form4.password.value.length==0){
alert("請輸入正確的密碼!");
form4.password.focus();
return false;
}

}
</script>
<style type="text/css">
<!--
#Layer1 {
position:absolute;
left:16px;
top:442px;
width:276px;
height:239px;
z-index:1;
}
#Layer2 {
position:absolute;
left:29px;
top:305px;
width:181px;
height:137px;
z-index:2;
}
-->
</style>
</head>

<body>
<div id="Layer1" style="left: 16px; width: 369px;">
<form id="form4" name="form4" method="post" action="loginControl.jsp">
<table border="0" style="top: 443px; left: 17px; width: 240px; height: 240px;">
<tr>
<td colspan="3"> <div align="center"><strong>用戶登錄</strong></div></td>
</tr>
<tr>
<td ><div align="right"><strong>用戶名:</strong></div></td>
<td colspan="1"><input type="text" name="name" /></td>
</tr>
<tr>
<td ><div align="right"><strong>密 碼:</strong><strong> </strong></div></td>
<td colspan="1"><input type="password" name="password" /></td>
</tr>
<tr>
<td height="37" colspan="3">
<label>
<input type="submit" name="Submit" value="登錄"onclick="javascript:return(checkform());" />

</label>
<input type="reset" name="reset" value="重填" />

</td>
</tr>
</table>
</form>
</div>
<div id="Layer2"> <img src=2.jpg width="120" height="120"/></div>
<label></label>
</body>
</html>

loginControl.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="tdb.jsp"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<style type="text/css">
<!--
#Layer1 {
position:absolute;
left:9px;
top:363px;
width:218px;
height:133px;
z-index:1;
}
-->
</style>
<head>
<title>My JSP 'loginControl.jsp' starting page</title>
</head>
<body>
<%
String name= request.getParameter("name");
String password= request.getParameter("password");
System.out.println("成功11111");
sql="SELECT * FROM tdb WHERE user_Name='"+name+"' AND user_Pwd='"+password+"'";
rs = smt.executeQuery(sql);
if(!rs.next())
{%>
<script type="text/javascript">
alert("用戶名和密碼不正確!!!");
window.location.href='index.jsp';
</script><%

}
response.sendRedirect("main.jsp");
%>
</body>
</html>

tdb.jsp

<%

Class.forName("oracle.jdbc.OracleDriver");

java.sql.Connection con=null;
con=java.sql.DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:ABC","zhan","123");
java.sql.Statement smt=con.createStatement();
java.sql.ResultSet rs;
java.sql.PreparedStatement ps;
String sql;
%>

9. 做一個web登錄界面,login.jsp裡面進行登錄,loginservlet進行登錄處理,然後轉回login.jsp進行顯示

首先,你jsp跳轉到Servlet是用哪種方法傳值的,是form表單提交,還是用連接(&loginok=true)這樣的提交。無論怎樣提交。boolean loginok = req.getParameter(loginok);也不對啊。req是什麼類型的啊?你的loginok是放在session裡面的。所以先創建session對象,然後在用session的內置方法獲取loginok的值。HttpSession session = request.getSession();然後在boolean loginok = session.getAttribute("loginok");
下面是我自己登陸用的Servlet希望可以幫到你:
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String userName = "";
String userPwd = "";
String flag = "";
flag = request.getParameter("flag");
if (flag == null) {
flag = "";
}
if (flag.equals("back")) {
HttpSession session = request.getSession();
session.invalidate();
flag = "";
response.sendRedirect("/MicroBlog/initServlet");
} else {
boolean bool = false;
action login = new action();
try {
RequestDispatcher rd = null;
request.setCharacterEncoding("UTF-8"); // 中文轉碼
response.setCharacterEncoding("UTF-8");

userName = request.getParameter("name"); // 獲得用戶登錄名
userPwd = request.getParameter("pwd"); // 獲得用戶密碼

bool = login.getLogin(userName, userPwd);
HttpSession session = request.getSession();
if (bool) { // 登陸成功
UserForm userForm = login.getUser();
ArrayList<String> guanList = login.getGuan(userForm.getId());
ArrayList<ExForm> expList = login.getExp();
session.setAttribute("exp", expList);
session.setAttribute("user", userForm);
session.setAttribute("guan", guanList);
rd = request.getRequestDispatcher("user.jsp");

} else {
rd = request.getRequestDispatcher("error.jsp");
}

rd.forward(request, response);

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

閱讀全文

與jsp登陸界面源碼相關的資料

熱點內容
javaweb程序設計郭 瀏覽:247
gm聲望命令 瀏覽:484
pdf轉換器電腦版免費 瀏覽:41
解壓歌曲什麼歌最好 瀏覽:151
諾貝爾pdf 瀏覽:967
雲伺服器快速安裝系統原理 瀏覽:788
蘋果騰訊管家如何恢復加密相冊 瀏覽:115
手機軟體反編譯教程 瀏覽:858
sqlserver編程語言 瀏覽:650
gpa國際標准演算法 瀏覽:238
伺服器編程語言排行 瀏覽:947
怎麼下載快跑app 瀏覽:966
小紅書app如何保存視頻 瀏覽:172
如何解開系統加密文件 瀏覽:811
linux切換root命令 瀏覽:283
c編譯之後界面一閃而過怎麼辦 瀏覽:880
怎麼看ic卡是否加密 瀏覽:726
lgplc編程講座 瀏覽:809
cnc手動編程銑圓 瀏覽:724
cad中幾種命令的意思 瀏覽:328