java web 使用jdbc 过程错误记录
2017-04-25 21:49
357 查看
1、
HTTP Status 404 - /work_03/main.jsp%20
2、注意使用 if 时的括号
举例:
3、 在tomcat上面建立连接池时
然后需要在 WEB-INF文件中的 web.xml (没有的话自己创建) 中进行配置,
这样就可以进行连接了,建立连接的代码:
更新
HTTP Status 404 - /work_03/main.jsp%20
错误原因: %20 代表的是空格的编码,在jsp应该是名字写的有错误,后面跟了一个空格 例如:<jsp:forward page="index.jsp " /> index.jsp后面跟了一个空格,就会出现错误
2、注意使用 if 时的括号
举例:
<% if(name.equals("")){ String d = "用户名不能为空,重新输入"; request.setAttribute("yn", d); %> <jsp:forward page = "index_02.jsp" /> <% }%>
3、 在tomcat上面建立连接池时
首先在web工程下的 META-INF 文件下面创建 context.xml 文件,里面时数据源参数配置信息 例如:
<?xml version="1.0" encoding="UTF-8"?> <Context> <Resource name = "jdbc/mysql" type = "javax.sql.DataSource" auth = "Container" driverClassName = "com.mysql.jdbc.Driver" url = "jdbc:mysql://localhost:3306/students" username = "root" password = "123456" maxActive = "4" maxIdle = "2" maxWait = "6000" /> </Context>
然后需要在 WEB-INF文件中的 web.xml (没有的话自己创建) 中进行配置,
<?xml version="1.0" encoding="UTF-8"?> <xml-body> <resource-ref> <description>mysql数据库连接池</description> <!--这里的名称与上面context.xml中的 name属性值一致--> <res-ref-name>jdbc/mysql</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth> <res-sharing-scope>Shareable</res-sharing-scope> </resource-ref> </xml-body>
这样就可以进行连接了,建立连接的代码:
// 导入的包 <%@page import = "java.sql.*,javax.sql.*,javax.naming.*" %> // 创建连接 Context ctx = new InitialContext(); DataSource ds =(DataSource)ctx.lookup("java:comp/env/jdbc/mysql"); Connection conn = ds.getConnection();
更新
相关文章推荐
- 关于Sikuli使用过程中java.lang.UnsatisfiedLinkError错误的解决
- java使用过程中知识点记录
- 深入分析JavaWeb Item28 -- 使用JDBC对数据库进行CRUD
- 【JavaWeb-2】JDBC的1个类3个接口、使用步骤、连接关闭优化、防SQL注入优化
- java_web 第三课servlet使用jdbc连接数据库
- java 中jdbc的使用练习-错误 mysql access denied for user odbc @localhost
- Java Web Service - java-json.jar包的使用以及JDBC的配置链接
- 开发环境-Windows下搭建JAVA Web开发环境(含Tomcat+MySQL)-过程记录
- java.lang.OutOfMemoryError: PermGen space及其解决方法【使用webservice请求web服务的时候报此错误】
- com.microsoft.sqlserver.jdbc.SQLServerException: 驱动程序无法通过使用安全套接字层(SSL)加密与 SQL Server 建立安全连接。错误:“java
- 【java工具】使用jdbc访问数据库获取某个存储过程信息及下面参数信息
- Java使用中菜鸟常犯的一些错误记录
- java web 使用jdbc 链接sql server 2008找不到驱动类的问题
- javaweb开发过程中的错误总结
- asp.net Web项目中使用Log4Net进行错误日志记录
- Java Web Project自定义错误页面,log4j记录日志。
- JDBC使用MySQL存储过程错误
- JAVA的WEB项目乱码,起因于tomcat 7 jdbc pool的使用
- JavaWeb开发使用Cookie创建-获取-持久化、自动登录、购物记录、作用路径
- [Exception JavaWeb 1] - Cause: com.microsoft.sqlserver.jdbc.SQLServerException: '@P2' 附近有语法错误。