首页源码jsp源码下载,jsp登陆界面源代码

jsp源码下载,jsp登陆界面源代码

编程之家2023-10-31221次浏览

大家好,关于jsp源码下载很多朋友都还不太明白,不过没关系,因为今天小编就来为大家分享关于jsp登陆界面源代码的知识点,相信应该可以解决大家的一些困惑和问题,如果碰巧可以解决您的问题,还望关注下本站哦,希望对各位有所帮助!

jsp源码下载,jsp登陆界面源代码

网上下的jsp源码要怎么用

楼上的乱说...有那个人做JSP用MS的IIS做服务器的还用JRun...faint

具体的你应该看你下的是什么类型的源码咯,测试可以直接丢到tomcat的webapp下面试试,然后运行tomcat就可以了,注意不是全部考进去,你考进去的文件夹的跟目录一定要有一个WEB-INF的文件夹,这样才符合servlet的标准才能被tomcat认可.

如果只是留言版之类的话不用配置数据库的就可以直接浏览了,如果有数据库的配置的话应该详情参看下载的源码的readme了

jsp登陆界面源代码

1、login.jsp文件

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

pageEncoding="GB18030"%>

jsp源码下载,jsp登陆界面源代码

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

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

<html>

<head>

<title>登录页面</title>

</head>

jsp源码下载,jsp登陆界面源代码

<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>

扩展资料:

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:\Users\win8\workspace\Login\image\9dcbdc339e72a5663b5c289fb5573c13_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>

jsp+servlet实现文件上传与下载源码

上传:

需要导入两个包:commons-fileupload-1.2.1.jar,commons-io-1.4.jar

import java.io.File;

import java.io.IOException;

import java.util.List;

import javax.servlet.ServletException;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import org.apache.commons.fileupload.FileItem;

import org.apache.commons.fileupload.disk.DiskFileItemFactory;

import org.apache.commons.fileupload.servlet.ServletFileUpload;

/**

*上传附件

*@author new

*

*/

public class UploadAnnexServlet extends HttpServlet{

private static String path="";

public void doGet(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException{

doPost(request, response);

}

/*

* post处理

*(non-Javadoc)

*@see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)

*/

public void doPost(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException{

path= this.getServletContext().getRealPath("/upload");

try{

DiskFileItemFactory factory= new DiskFileItemFactory();

ServletFileUpload up= new ServletFileUpload(factory);

List<FileItem> ls= up.parseRequest(request);

for(FileItem fileItem: ls){

if(fileItem.isFormField()){

String FieldName= fileItem.getFieldName();

//getName()返回的是文件名字普通域没有文件返回NULL

// String Name= fileItem.getName();

String Content= fileItem.getString("gbk");

request.setAttribute(FieldName, Content);

} else{

String nm= fileItem.getName().substring(

fileItem.getName().lastIndexOf("\\")+ 1);

File mkr= new File(path, nm);

if(mkr.createNewFile()){

fileItem.write(mkr);//非常方便的方法

}

request.setAttribute("result","上传文件成功!");

}

}

} catch(Exception e){

e.printStackTrace();

request.setAttribute("result","上传失败,请查找原因,重新再试!");

}

request.getRequestDispatcher("/pages/admin/annex-manager.jsp").forward(

request, response);

}

}

下载(i/o流)无需导包:

import java.io.IOException;

import java.net.URLEncoder;

import javax.servlet.ServletException;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

/**

*下载文件

*@author

*

*/

public class DownloadFilesServlet extends HttpServlet{

/**

*

*/

private static final long serialVersionUID= 8594448765428224944L;

public void doGet(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException{

doPost(request, response);

}

/*

*处理请求

*(non-Javadoc)

*@see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)

*/

public void doPost(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException{

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

System.out.print("dddddddddd:"+ name);

// web绝对路径

String path= request.getSession().getServletContext().getRealPath("/");

String savePath= path+"upload";

//设置为下载application/x-download

response.setContentType("application/x-download");

//即将下载的文件在服务器上的绝对路径

String filenamedownload= savePath+"/"+ name;

//下载文件时显示的文件保存名称

String filenamedisplay= name;

//中文编码转换

filenamedisplay= URLEncoder.encode(filenamedisplay,"UTF-8");

response.addHeader("Content-Disposition","attachment;filename="

+ filenamedisplay);

try{

java.io.OutputStream os= response.getOutputStream();

java.io.FileInputStream fis= new java.io.FileInputStream(

filenamedownload);

byte[] b= new byte[1024];

int i= 0;

while((i= fis.read(b))> 0){

os.write(b, 0, i);

}

fis.close();

os.flush();

os.close();

} catch(Exception e){

}

}

}

OK,关于jsp源码下载和jsp登陆界面源代码的内容到此结束了,希望对大家有所帮助。

临沂企业建站?临沂网站设计哪家好源码中国?中国最好的源码网站