ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

Day16

2022-01-20 21:32:56  阅读:125  来源: 互联网

标签:Code String QueryBookException Day16 static public View


 exception包QueryBookException类

public class QueryBookException extends RuntimeException {

    public QueryBookException() {
    }

    public QueryBookException(String message) {
        super(message);
    }

    public QueryBookException(Throwable cause) {
        super(cause);
    }

    public QueryBookException(String message, Throwable cause) {
        super(message, cause);
    }

}
View Code

utils包DbcpUtil类

public class DbcpUtils {

        public static DataSource dataSource;

        static{
            try {
                String myFile = "dbcp.properties";
                InputStream in = DbcpUtils.class.getClassLoader().getResourceAsStream(myFile);
                Properties p = new Properties();
                p.load(in);
                dataSource = BasicDataSourceFactory.createDataSource(p);
            }  catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
        

        // 获取数据源
        public static DataSource getDataSource(){
            return dataSource;
        }
        
        // 获取连接   
        public static Connection getConnection() throws SQLException {
            return dataSource.getConnection();
        }
}
               
View Code

utils包SetPhotoPath类

public class SetPhotoPath {
    public static  String makeDir(String storeDirectory ,String filename){
        int hashCode = filename.hashCode();
      
        int dir1 = hashCode&0xf;

        int dir2 = (hashCode&0xf)>>4;

        String newPath = "/"+dir1+"/"+dir2;
        File file = new File(storeDirectory, newPath);

        if(!file.exists()){
            file.mkdirs();
        }

        return newPath;
    }
}
View Code

1.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ include file="/1.jsp"  %>

<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
pageContext.setAttribute("basePath", basePath);
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">

    <title>分类列表</title>
    <style>
        table{
            text-align: center;
            font-size: 12px;
        }
    </style>
  </head>
View Code

5.jsp

<%@ 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 '5.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>
       <jsp:forward page="/WEB-INF/3.jsp"></jsp:forward>
       <jsp:include page="/header.jsp"></jsp:include>
  </body>
</html>
View Code

addBook.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/header.jsp" %>
    <br/>
    <hr/>
    <br/>
    <!--
        文件上传时:
            |--- 表单中必须要采用的方式 enctype
      -->
    <form action="${basePath}servlet/ControlServlet?op=addBook" method="post" enctype="multipart/form-data" >
        <table border="1">
            <tr>
                <td>书名</td>
                <td><input type="text" name="name"></td>
            </tr>
            <tr>
                <td>作者</td>
                <td><input type="text" name="author"></td>
            </tr>
            <tr>
                <td>描述</td>
                <td><input type="text" name="description"></td>
            </tr>
            <tr>
                <td>单价</td>
                <td><input type="text" name="price"></td>
            </tr>
            <tr>
                <td>图片</td>
                <td><input type="file" name="photoname"></td>
            </tr>
            <tr>
                <td>图片预览</td>
                <td><img src="${basePath}images${b.path}/${b.photoName}" ></td>
            </tr>
            <tr>
                <td>出版社</td>
                <td><input type="text" name="publish"></td>
            </tr>
            <tr>
                <td>分类</td>
                <td><select name="categoryId">
                    <c:forEach items="${cs}" var="c" >
                        <option value="${c.id}" >${c.name}</option>
                    </c:forEach>
                </select></td>
            </tr>
            <tr>
                <td colspan="2"><input type="submit" value="添加图书"></td>
            </tr>
        </table>
    </form>
</body>
</html>
View Code

addCategory.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/header.jsp"  %>
<br/>
<hr/>
<br/>
    <!--${pageContext.request.contextPath}是为了获取这个路径:http://localhost:8888/bookstore -->
    <form action="${pageContext.request.contextPath}/servlet/ControlServlet?op=addCategory" method="post" >
        <table border="1">
            <!-- 第1行  -->
            <tr>
                <td>分类名称</td>
                <td><input type="text" name="name"></td>
            </tr>
            <!-- 第2行  -->
            <tr>
                <td>分类描述</td>
                <td><textarea rows="3" cols="15" name="description"></textarea>
                </td>
            </tr>
            <!-- 第3行  -->
            <tr>
                <td colspan="2"><input type="submit" value="添加分类"></td>
            </tr>
        </table>
    </form>
</body>
</html>
View Code

 

标签:Code,String,QueryBookException,Day16,static,public,View
来源: https://www.cnblogs.com/headl-voi/p/15828104.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有