其他分享
首页 > 其他分享> > Day16

Day16

作者:互联网

 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