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安全性问题的更多相关文章

  1. 比较page、request、session、application的使用范围(转自用)

    (1)直接在web contain中进行对象的实例化. 内置对象 类型 作用域 pageContext javax.servlet.jsp.pageContext page request javax ...

  2. JSP内置对象--web安全性及config对象的使用 (了解即可)

    tomcat服务器配置的时候,在虚拟目录中必须存在一个WEB-INF文件夹,但是访问的时候并不能发现这个文件夹.改成WEB-INFs就可以看到. 所以WEB-INF文件夹不轻易让用户看到,那么其安全性 ...

  3. JSP内置对象之WEB安全性及config对象

    一.WEB-INF的安全性是最高的. 在Java EE的标准中,Web目录中的WEB-INF是必须存在的,而且此文件夹的安全性是最高的,在各个程序的开发中,基本上都将一些配置信息保存在此文件夹中.在定 ...

  4. JSP的安全性

    以下内容引用自http://wiki.jikexueyuan.com/project/jsp/security.html: JavaServer Pages和Servlets有几种可用的机制可以使We ...

  5. 浅谈JSP注释

    HTML注释 JSP文件是由HTML尿急和嵌入的Java程序片段组成的,所以在HTML中的注释同样可以在JSP文件中使用.注释格式:<!--注释内容--> <!-- 欢迎提示信息! ...

  6. JSP内置对象之request对象【学习笔记】

    request对象是JSP中重要的对象,每个request对象封装着一次用户的请求,并且所有的请求参数都被封装在request对象中,因此request对象是获取请求参数的重要途径. 一.获取请求头与 ...

  7. web安全性测试用例

    建立整体的威胁模型,测试溢出漏洞.信息泄漏.错误处理.SQL 注入.身份验证和授权错误. 1.   输入验证 客户端验证 服务器端验证(禁用脚本调试,禁用Cookies) 1.输入很大的数(如4,29 ...

  8. 防止 jsp被sql注入的五种方法

    一.SQL注入简介 SQL注入是比较常见的网络攻击方式之一,它不是利用操作系统的BUG来实现攻击,而是针对程序员编程时的疏忽,通过SQL语句,实现无帐号登录,甚至篡改数据库. 二.SQL注入攻击的总体 ...

  9. JSP数据交互

    JSP数据交互   一.jsp中java小脚本 1.<% java代码段%> 2.<% =java表达式%>不能有分号 3.<%!成员变量和函数声明%>二.注释 1 ...

随机推荐

  1. 【Maven】1.使用myecplise配置自己的Maven配置,不使用默认的maven

    [好文章]参考地址: http://www.cnblogs.com/luotaoyeah/p/3764533.html ---------------------------------------- ...

  2. 跟着Sedgewick学算法(week 1 ElementarySort)

     链接https://www.evernote.com/shard/s408/sh/dbe0167f-20e0-41c4-a49b-75717ad98695/461148482ffb6add092be ...

  3. Ubuntu14.04进行配置符号链接arm-2009q3.tar.bz2

    进入系统终端:cd /usr/local/ 创建文件夹arm:并进去arm,将winshare共享文件夹里面的文件/arm-2009q3复制到arm文件夹中; tar -jxvf  arm-2009q ...

  4. CountDownLatch模拟高并发测试代码

    直接上代码进行验证吧 /** * 通过countdownlatch的机制,来实现并发运行 * 模拟200个并发测试 * @author ll * @date 2018年4月18日 下午3:55:59 ...

  5. 使用PowerDesigner进行代码生成

    很多代码生成器都选择了从表结构来生成领域模型,这样的方案有一个前提,就是领域模型和数据库表结构是同构的,也就是说领域模型中的类和数据库中的记录结构十分吻合,这样数据库表结构可以简单的直接映射到领域模型 ...

  6. PHP使用mysqli连接MySQL数据库

    使用mysqli函数库连接MySQL,支持面向对象和面向过程两种方式: 1.面向对象的使用方式 建立一个连接 $db = new mysqli('localhost', 'root', '123456 ...

  7. vsftpd 配置:chroot_local_user与chroot_list_enable userlist_enable userlist_deny详解

    默认情况下,如果设置了 userlist_enable=YES,当 userlist_deny 选项设置为 YES 的时候,userlist_file=/etc/vsftpd.userlist 中列出 ...

  8. Laravel之队列

    一.配置 队列配置文件存放在config/queue.php .在该文件中你将会找到框架自带的每一个队列驱动的连接配置,包括数据库.Beanstalkd. IronMQ. Amazon SQS. Re ...

  9. eclispe查看jdk源码后特别卡顿导致未响应解决

    第一步:Eclipse -> Preferences -> General -> Startup and Shutdown.不要勾选 RSE UI. 第二步:Eclipse -> ...

  10. vue-router push

    //push 方法一 对象 // this.$router.push({path:'HelloWorld2'}); //push 方法二 命名的路由 // this.$router.push({nam ...