JSP页面中使用JSTL标签出现无法解析问题解决办法

时间:2022-11-16 15:00:18



http://www.cnblogs.com/xdp-gacl/p/3951172.html  比较清楚地描述了问题((另外关注数据库访问功能技术)



1、jsp页面需要放到容器下项目才能正常访问,因为jsp代码需要容器解析为纯html代码


2、导入两个jar包 到tomcat下的lib, 然后重启下tomcat容器


http://bbs.csdn.net/topics/390266541 

http://jingyan.baidu.com/article/ab0b56309427b9c15afa7dd7.html

(http://www.apache.org/dist)


3、如果再有其他问题,肯能参考 http://www.cnblogs.com/interestudy/archive/2012/10/31/2748773.html 能够解决


<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="java.io.*,java.util.*,java.sql.*"%>
<%@ page import="javax.servlet.http.*,javax.servlet.*" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%>


<html>
<head>
<title> select 操作</title>
</head>
<body>
<!--
JDBC 驱动名及数据库 URL 
数据库的用户名与密码,需要根据自己的设置
useUnicode=true&characterEncoding=utf-8 防止中文乱码
-->
<sql:setDataSource var="snapshot" driver="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/test"
user="root"  password="Dap1234$"/>
<!--
插入数据
-->
<sql:update dataSource="${snapshot}" var="result">
INSERT INTO t_test (name,year) VALUES ('菜鸟教程移动站', 2017);
</sql:update>
<sql:query dataSource="${snapshot}" var="result">
SELECT * from t_test;
</sql:query>
<c:forEach var="row" items="${result.rows}">
${row.id}-->${row.name}-->${row.year}--><br>
</c:forEach>
<p>
Haha
</p>

<table border='1'>
<tr>
<td>id</td>
<td>名称</td>
<td>年份</td>
</tr>
<%
Class.forName("org.gjt.mm.mysql.Driver").newInstance();    
String url ="jdbc:mysql://localhost/test?user=root&password=Dap1234$&useUnicode=true&characterEncoding=utf-8"; 
//myDB为数据库名    
Connection conn= DriverManager.getConnection(url);  
out.println(conn);
Statement ps = conn.createStatement();
ResultSet rs = ps.executeQuery("select * from t_test");
while(rs.next()){
String id = rs.getString("id");
String name = rs.getString("name");
String year = rs.getString("year");
%>
<tr>
<td><%=id%></td>
<td><%=name%></td>
<td><%=year%></td>
</tr>
<%
}
/*
import java.sql.*;     
//Class.forName("org.gjt.mm.mysql.Driver").newInstance();     
Class.forName("com.mysql.jdbc.Driver");     
//String url ="jdbc:mysql://localhost/test?user=root$&password=Dap1234$&useUnicode=true&characterEncoding=utf-8";     
String url ="jdbc:mysql://localhost:3306/test"; </pre><pre name="code" class="java">//myDB为数据库名     
Connection conn= DriverManager.getConnection(url,"root","root");      
Statement stmtNew=conn.createStatement();  
*/
%>

</table>
<p>
--------------------
</p>
<%
out.println("god");
%>
</body>
</html>




http://www.cnblogs.com/xdp-gacl/p/3951172.html