jsp安全性问题
jsp项目不同jsp之间假设只通过超链接进行跳转,安全性太低,不能满足现实生活中对安全性的要求!
为了提高安全性。能够通过Servlet进行跳转,进行跳转的时候为了进一步实现其安全性,能够通过间jsp文件放在WEB-INF目录里面。这样安全性就能得到提升。可是问题伴随而来,放在WEB-INF目录里面,怎样进行訪问?
能够实现的一种思路:另建一个Servlet类作为页面跳转的中转站!将须要使用到的放在WEB-INF目录里面的文件通过使用id进行区分,在须要訪问到这些jsp文件的时候直接通过中转站然后获得要訪问的jsp的id,即能够进行对应的页面跳转。
新建的Servlet类代码例如以下:
package cn.edu.servlet;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class MNG extends HttpServlet {
private static final long serialVersionUID = 1L;
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String id = request.getParameter("id");
//从页面获得的用户区分跳转页面的id
System.out.println("id="+id);
//我调试的时候使用的,并没实用
if(id.equals("1")){
request.getRequestDispatcher("/index.jsp").forward(request,response);
}else if(id.equals("2")){
request.getRequestDispatcher("/WEB-INF/admin/add.jsp").forward(request,response);
}else if (id.equals("3")) {
request.getRequestDispatcher("/WEB-INF/admin/bisai.jsp").forward(request,response);
}else if (id.equals("4")) {
request.getRequestDispatcher("/WEB-INF/admin/gamema.jsp").forward(request,response);
}else if (id.equals("5")) {
request.getRequestDispatcher("/WEB-INF/admin/manager.jsp").forward(request,response);
}else if (id.equals("6")) {
request.getRequestDispatcher("/WEB-INF/admin/message.jsp").forward(request,response);
}else if (id.equals("7")) {
request.getRequestDispatcher("/WEB-INF/admin/modify.jsp").forward(request,response);
}else if (id.equals("8")) {
request.getRequestDispatcher("/WEB-INF/admin/pk.jsp").forward(request,response);
}else if (id.equals("9")) {
request.getRequestDispatcher("/WEB-INF/admin/result.jsp").forward(request,response);
}
}
}
进行跳转的页面代码例如以下:
<form action="AddServlet" method="post">
<label>比赛编号:</label><input type="text" name="id" placeholder="请输入比赛编号"/><br />
<label>比赛名称:</label><input type="text" name="gamename" placeholder="请输入比赛名称"/><br />
<label>比赛时间:</label><input type="text" name="gametime" placeholder="*格式:YYYY.MM.DD"/><br />
<label>比赛地点:</label><input type="text" name="gameaddress" placeholder="请输入比赛地点"/><br />
<label>人数限制:</label><input type="text" name="gamenum" placeholder="*格式:请填写整数"/><br />
<label>报名截止:</label><input type="text" name="deadline" placeholder="*格式:YYYY.MM.DD"/><br />
<!--
<form action="" method="post"><input type="submit" value="加入"></form>
<form action="tennis_game/WebRoot/WEB-INF/bisai.jsp" method="post"><input type="button" value="返回"></form>
-->
<button type="submit" value="加入">加入</button>
<a href="MNG?id=3"><button type="button" value="返回">返回</button></a>
</form>
通过id进行跳转。
还有一种方法比較简单,不用讲所有的jsp文件所有都放在WEB-INF文件以下。只通过将登陆页面要跳转的目标页面放入WEB-INF文件下即可了,通过登陆页面跳转的 Servlet类中通过会话对象session获取用户的账户密码,然后在每个页面的開始通过JavaScript来验证是否登陆。
function checkNull(){
if(document.getElementById("id").value=="" || document.getElementById("id").value==null)
{
alert("帐号不能为空!");
document.getElementById("id").focus();
document.getElementById("id").select();
return false;
}
if(document.getElementById("pass").value=="" || document.getElementById("pass").value==null)
{
alert("密码不能为空!
");
document.getElementById("pass").focus();
document.getElementById("pass").select();
return false;
}
if(document.getElementById("password").value!=document.getElementById("password2").value)
{
alert("两次密码输入不一致!");
document.getElementById("password").focus();
document.getElementById("password").select();
return false;
}
if(document.getElementById("name").value=="" || document.getElementById("name").value==null)
{
alert("姓名不能为空!");
document.getElementById("name").focus();
document.getElementById("name").select();
return false;
}
else return true;
}
管理员登录界面确保安全性:
<%
String adminid = (String)session.getAttribute("adminname");
if(adminid==null){
%>
<script type="text/javascript" language="javascript">
alert("你还没有登录。。。");
window.document.location.href="/TennisMatch/welcome";
</script>
<%
}
%>
jsp安全性问题的更多相关文章
- 比较page、request、session、application的使用范围(转自用)
(1)直接在web contain中进行对象的实例化. 内置对象 类型 作用域 pageContext javax.servlet.jsp.pageContext page request javax ...
- JSP内置对象--web安全性及config对象的使用 (了解即可)
tomcat服务器配置的时候,在虚拟目录中必须存在一个WEB-INF文件夹,但是访问的时候并不能发现这个文件夹.改成WEB-INFs就可以看到. 所以WEB-INF文件夹不轻易让用户看到,那么其安全性 ...
- JSP内置对象之WEB安全性及config对象
一.WEB-INF的安全性是最高的. 在Java EE的标准中,Web目录中的WEB-INF是必须存在的,而且此文件夹的安全性是最高的,在各个程序的开发中,基本上都将一些配置信息保存在此文件夹中.在定 ...
- JSP的安全性
以下内容引用自http://wiki.jikexueyuan.com/project/jsp/security.html: JavaServer Pages和Servlets有几种可用的机制可以使We ...
- 浅谈JSP注释
HTML注释 JSP文件是由HTML尿急和嵌入的Java程序片段组成的,所以在HTML中的注释同样可以在JSP文件中使用.注释格式:<!--注释内容--> <!-- 欢迎提示信息! ...
- JSP内置对象之request对象【学习笔记】
request对象是JSP中重要的对象,每个request对象封装着一次用户的请求,并且所有的请求参数都被封装在request对象中,因此request对象是获取请求参数的重要途径. 一.获取请求头与 ...
- web安全性测试用例
建立整体的威胁模型,测试溢出漏洞.信息泄漏.错误处理.SQL 注入.身份验证和授权错误. 1. 输入验证 客户端验证 服务器端验证(禁用脚本调试,禁用Cookies) 1.输入很大的数(如4,29 ...
- 防止 jsp被sql注入的五种方法
一.SQL注入简介 SQL注入是比较常见的网络攻击方式之一,它不是利用操作系统的BUG来实现攻击,而是针对程序员编程时的疏忽,通过SQL语句,实现无帐号登录,甚至篡改数据库. 二.SQL注入攻击的总体 ...
- JSP数据交互
JSP数据交互 一.jsp中java小脚本 1.<% java代码段%> 2.<% =java表达式%>不能有分号 3.<%!成员变量和函数声明%>二.注释 1 ...
随机推荐
- java随机生成字符串(字符随机生成类 生成随机字符组合)
原文:http://www.jb51.net/article/45006.htm package p2p_web; import java.util.ArrayList; import java.ut ...
- 【微信】微信小程序 应用内的页面跳转在添加了tab以后就跳转不成功的问题解决
在微信小程序中,本来应用页面内绑定在按钮上跳转页面可以成功,但是将页面添加在tab以后就不能实现跳转了 原本代码如下: //事件处理函数 bindViewTap: function() { wx.na ...
- docer中运行crontab
1 安装 sudo apt-get install cron 2 启动 start cron 3 列出所有本机启动crontab任务 ls -l /etc/init.d 列出所有自建cron任务 ...
- 基于pydash临控linux服务器
pydash项目地址:https://github.com/k3oni/pydash 一.安装过程 1.安装pip dnf install git python-pip -ypip install v ...
- wsdl2java在mac中点配置
1.打开终端,默认是用户目录,输入以下命令: ls -a 显示隐藏文件 2.打开.bash_profile,输入以下命令 open .bash_profile 配置JAVA_HOME,AXIS2_HO ...
- scrapy爬虫程序xpath中文编码报错
2017-03-23 问题描述: #选择出节点中“时间”二字 <h2>时间</h2> item["file_urls"]= response.xpath(& ...
- snmp弱口令引起的信息泄漏
0x00 snmp协议简介 snmp协议即简单网络管理协议(SNMP,Simple Network Management Protocol).目前一共有3个版本:V1,V2c,V3.V3是最新的版本, ...
- mongoDB - 插入数据
db.use.js /** * 使用前:先安装node环境.express.mongodb. * * 1.1 安装Node * 1.2 npm i -D express mongodb &&a ...
- 隐藏ion-nav-back-button的文字
<ion-nav-bar class="bar-positive"> <ion-nav-back-button> </ion-nav-back-but ...
- wps如何设置文字环绕图片
wps在编辑一些文字的时候,经常会插入一些图片,但是插入图片后,文字和图片就被分离开来,整体显得没有那么美观整洁,这个时候就用到了软件的文字环绕功能,那么具体如何设置呢,接下来看教程. 首先打开wps ...