JSP——内置对象application out session request response+EL+uplaod+download

来源:互联网 发布:爱淘宝每日红包 编辑:程序博客网 时间:2024/06/06 04:16

JSP——内置对象application out session  request response+EL+uplaod+download

JSP内置对象application  out  session   request    response

<%=pageContext.getPage().toString() %><br>
   <%=pageContext.getOut() %><br>
   
  
   
    <%=pageContext.setAttribute("", "") %><br>
        <%=page.toString() %><br>
        
    <%=request.setAttribute("", "") %><br>
    <%=response.sendRedirect("") %><br>
    <%=session.setAttribute("", "") %><br>
    <%=application.setAttribute("", "") %><br>
    <%=out.print("") %><br>
    
    <%=config.getInitParameter("") %>
    
    <%=pageContext.getException() %>

    
    
   <%=exception %> 







JSTL  EL

EL ExpressionLanguage (表达式语言)

 

功能:代替js中的复杂语言








<%@page import="com.jredu.session.entity.User"%><%@ page language="java" import="java.util.*" pageEncoding="utf-8"%><%@ page  isELIgnored="false" isErrorPage="true"%><%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";request.setCharacterEncoding("utf-8");/* String c1= request.getParameter("c1"); */request.setAttribute("c5","zhang");List list=new ArrayList();User user=new User("诸葛亮1","3333");list.add(user);     user=new User("诸葛亮2","3333");     list.add(user);   Map map=new HashMap();   map.put("n316","张宇峰");  request.setAttribute("n316map",map); session.setAttribute("sessss", list);     session.setAttribute("sesss", user);session.setAttribute("sess", "我是一个session对话");application.setAttribute("app", "我是一个全局变量application");%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html>  <head>    <base href="<%=basePath%>">        <title>My JSP 'show.jsp' starting page</title>    <meta http-equiv="pragma" content="no-cache"><meta http-equiv="cache-control" content="no-cache"><meta http-equiv="expires" content="0">    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"><meta http-equiv="description" content="This is my page"><!--<link rel="stylesheet" type="text/css" href="styles.css">-->  </head>    <body>  <%-- <%=c1 %>  --%>  ${param.c1}  ${requestScope.c5}  ${sessionScope.sess}  ${applicationScope.app}    ${sessionScope.sesss.name}      ${sessionScope.sessss[1].name}              ${requestScope.n316map.n316}         ${requestScope.n316map["n316"]}                 <%=exception %>           <br>  </body></html>

uplaod+download





<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%><%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html>  <head>    <base href="<%=basePath%>">        <title>My JSP 'chooseFile.jsp' starting page</title>    <meta http-equiv="pragma" content="no-cache"><meta http-equiv="cache-control" content="no-cache"><meta http-equiv="expires" content="0">    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"><meta http-equiv="description" content="This is my page"><!--<link rel="stylesheet" type="text/css" href="styles.css">--><script type="text/javascript">function upload(){document.baseForm.submit();}</script>  </head>    <body> <form action="myUpload/upload.jsp" enctype="multipart/form-data" method="post" name="baseForm">  <input type="file"  name="zz1"><br>   <input type="file"  name="zz2"><br> <input type="file"  name="zz3"><br> <input type="button" value="上传" onclick="upload()"><br>   <input type="text" name="c1"> <input type="submit" value="上传"> </form>  </body></html>

<%@page import="com.jspsmart.upload.Request"%><%@page import="com.jspsmart.upload.SmartUpload"%><%@page import="com.jspsmart.upload.File"%><%@ page language="java" import="java.util.*" pageEncoding="utf-8"%><%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";/* SmartUpload su=new SmartUpload();su.initialize(pageContext);su.upload();su.save("zyfupload");com.jspsmart.upload.File file=su.getFiles().getFile(0);String filepath="zyfupload\\";filepath+=file.getFieldName();//文件另存为file.saveAs(filepath, SmartUpload.SAVE_VIRTUAL); */SmartUpload su=new SmartUpload();String  c1=null;try{su.initialize(pageContext);//允许上传类型su.setAllowedFilesList("gif,jpg,png,doc");//不允许su.setDeniedFilesList("jsp,asp,php,aspx,html,htm,exe,bat");//单个文件的最大限度su.setMaxFileSize(2000000000);//所有上传文件的总限度//su.setTotalMaxFileSize(5000000);//执行上传su.upload();Request rq= su.getRequest();  c1=rq.getParameter("c1");su.save("zyfupload");File file=su.getFiles().getFile(0);file.saveAs("/zyfupload/"+file.getFileName(), su.SAVE_VIRTUAL); out.print(su.save("zyfupload")+"");}catch(Exception e){   out.print("上传格式不对");}%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html>  <head>    <base href="<%=basePath%>">        <title>My JSP 'upload.jsp' starting page</title>    <meta http-equiv="pragma" content="no-cache"><meta http-equiv="cache-control" content="no-cache"><meta http-equiv="expires" content="0">    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"><meta http-equiv="description" content="This is my page"><!--<link rel="stylesheet" type="text/css" href="styles.css">-->  </head>    <body> <br>  <%=c1%></body></html>

<%@page import="com.jspsmart.upload.SmartUpload"%><%@ page language="java" import="java.util.*" pageEncoding="utf-8"%><%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";String fileName=request.getParameter("fileName");if(fileName!=null){fileName=fileName.replaceAll(basePath, "");SmartUpload su=new SmartUpload();su.initialize(pageContext);su.downloadFile(fileName);}%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html>  <head>    <base href="<%=basePath%>">        <title>My JSP 'download.jsp' starting page</title>    <meta http-equiv="pragma" content="no-cache"><meta http-equiv="cache-control" content="no-cache"><meta http-equiv="expires" content="0">    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"><meta http-equiv="description" content="This is my page"><!--<link rel="stylesheet" type="text/css" href="styles.css">--><script type="text/javascript">function d1(obj){/* alert(obj.src); */window.location.href="myUpload/download.jsp?fileName="+obj.src;/* document.baseForm.action="myUpload/download.jsp?fileName="+obj.src;document.baseForm.submit(); */}</script>  </head>    <body>  <form action="" name="baseForm">   <img alt="" src="zyfupload/zhangyufeng.jpg" name="zyf1" onclick="d1(this)" > <br>  <img alt="" src="zyfupload/zhangyufeng.jpg" name="zyf2"> <br>  <img alt="" src="zyfupload/zhangyufeng.jpg" name="zyf3"> <br>  </form>   </body></html>





 
1 0
原创粉丝点击