本文目錄一覽:
- 1、運行JSP頁面顯示源碼
- 2、網上下的jsp源碼要怎麼用
- 3、jsp文件用IE打開出現的是源代碼?
- 4、jsp登陸界面源代碼
- 5、使用Servelet和JSP技術的應用系統綜合實例源代碼
- 6、jsp 是屬於客戶端還是服務端
運行JSP頁面顯示源碼
localhost:8080 tomcat的主頁打得開嗎?
打不開的話就是項目沒有配置到Tomcat,打得開的話新建一個運行再試試。
網上下的jsp源碼要怎麼用
需要部署到服務器中
找到菜單 window → Show View → Servers,打開Servers視圖標籤,部署的Tomcat 服務
在這個服務上右擊,選擇「Add Deployment」
在新打開的對話框中,有一個Project項,選擇要部署的項目
點擊「Finish」完成部署
這樣項目就部署到Tomcat裏面去了
jsp文件用IE打開出現的是源代碼?
JSP文件打開是需要部署到服務器端的,如tomcat
直接放到Webapps目錄下就可以了,步驟如下:
Tomcat的Webapps目錄是Tomcat默認的應用目錄,務器啟動時,會加載所有這個目錄 下的應用。
也可以將JSP程序打包成一個war包放在目錄下,服務器會自動解開這個war包,並在這個目錄下生成一個同名的文件夾。
一個war包就是有特 性格式的jar包,它是將一個Web程序的所有內容進行壓縮得到。
在程序執行中打包:
try{
string strjavahome = system.getproperty(“java.home”);
strjavahome = strjavahome.substring(0,strjavahome.lastindexof(\\))+”\\bin\\”;
runtime.getruntime().exec(“cmd /c start “+strjavahome+”jar cvf hello.war c:\\tomcat5.0\\webapps\\root\\*”);
}
catch(exception e){system.out.println(e);}
webapps這個默認的應用目錄也是可以改變。
打開Tomcat的conf目錄下的server.xml文件,找到下面內容即可:
Host name=”localhost” debug=”0″ appBase=”webapps” unpackWARs=”true” autoDeloy=”true” xmlValidation=”falase” xmlNamespaceAware=”false”
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
tdinput 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
擴展資料:
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” “”
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” “”
html
head
meta http-equiv=”Content-Type” content=”text/html; charset=ISO-8859-1″
titleInsert 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” “”
html
head
meta http-equiv=”Content-Type” content=”text/html; charset=ISO-8859-1″
title登錄界面/title
/head
body background=”C:\Users\win8\workspace\Login\image\9dcbdc339e72a5663b5c289fb5573c13_10.jpg”
center
brbrbrbrbrbr
h1 style=”color:yellow”Login/h1
br
form name=”loginForm” action=”login_check.jsp” method=”post”
table Border=”0″
tr
td賬號/td
tdinput type=”text” name=”username”/td
/tr
tr
td密碼/td
tdinput type=”password” name=”password”
/td
/tr
/table
br
input type=”submit” value=”登錄” style=”color:#BC8F8F”
/form
/center
/body
/html
使用Servelet和JSP技術的應用系統綜合實例源代碼
它實現了Html語法中的java擴展(以 %,
%形式)。JSP與Servlet一樣,是在服務器端執行的。通常返回給客戶端的就是一個HTML文本,因此客戶端只要有瀏覽器就能瀏覽。
JSP技術使用Java編程語言編寫類XML的tags和scriptlets,來封裝產生動態網頁的處理邏輯。網頁還能通過tags和scriptlets訪問存在於服務端的資源的應用邏輯。JSP將網頁邏輯與網頁設計的顯示分離,支持可重用的基於組件的設計,使基於Web的應用程序的開發變得迅速和容易。
JSP(JavaServer Pages)是一種動態頁面技術,它的主要目的是將表示邏輯從Servlet中分離出來
jsp 是屬於客戶端還是服務端
JSP技術屬於客戶端技術,只不過他可以封裝處理邏輯,能讓處理邏輯和網頁設計分離,這就是你看到的源碼不一致的現象,但是這依然屬於客戶端技術
原創文章,作者:IADQ,如若轉載,請註明出處:https://www.506064.com/zh-hk/n/143587.html