jsp 中用户登陆系统欢迎界面用户名密码如果是汉字出现乱码,以及连接数据库时,出现乱码

爱疯1410 2014-03-01 05:45:48
wel.jsp
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.Connection"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.ResultSet"%>
<%@ page language="java" import="java.util.*,java.sql.*" pageEncoding="gb2312"%>
<%
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 'Wel.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>

<center>
恭喜登陆成功 <br>


<%

String userName = request.getParameter("user");
String passWord = request.getParameter("pass");

System.out.print(userName);


out.print("提交的用户名为:"
+ new String(userName.getBytes("ISO-8859-1"), "gb2312")
+ "<br>");
out.print("提交的密码为: "
+ new String(passWord.getBytes("ISO-8859-1"), "gb2312")
+ "<br>");
%>


<a href="Login.jsp">返回重新登陆</a>
<h1>用户信息列表</h1>
<%
int pageSize=3;//每页显示多少记录
int pageNow=1;//显示第几页
int rowcount=0;//共有几条记录
int pagecount=0;//共有几页
ResultSet rs=null;
Statement stm=null;
Connection con=null;


Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
String url = "jdbc:sqlserver://127.0.0.1:1433";

con = DriverManager.getConnection(url,"sa","123");
con.setCatalog("study");
stm=con.createStatement();

rs=stm.executeQuery("select count(*) from users");//查询总记录数


System.out.print(rs);


if(rs.next()){
rowcount=rs.getInt(1);
}//计算pagecount
if (rowcount % pageSize==0) {
pagecount=rowcount / pageSize;
}else {
pagecount=rowcount / pageSize+1;
}//查询要显示出的记录
stm=con.prepareStatement("select top "+pageSize+" * from users where userId not in(select top "+pageSize*(pageNow-1)+" userId from users)");

%>
<table border="1">
<tr><td>用户ID</td>
<td>用户名</td>
<td>密码</td>
<td>email</td>
<td>优先级</td>

</tr>
</table>
<%
while(rs.next()){
%>

<tr> <td><%=rs.getInt(1) %></td>
<td><%=rs.getString(2) %></td>
<td><%=rs.getString(3) %></td>
<td><%=rs.getString(4) %></td>
<td><%=rs.getInt(5) %></td>
<td><%=rowcount %></td>
</tr>

<%
}
%>
</body></center>
</html>
望高手解答,十分感谢。
...全文
1130 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
爱疯1410 2014-03-02
  • 打赏
  • 举报
回复
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<display-name></display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
我用myeslipes 开发的,这是我xml 文件,按照你说的在xml 中加入代码,显示错误啊,,望大师在看看啊,我的代码如下:
爱疯1410 2014-03-02
  • 打赏
  • 举报
回复
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<display-name></display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
我用myeslipes 开发的,这是我xml 文件,按照你说的在xml 中加入代码,显示错误啊,,望大师在看看啊,我的代码如下:
爱疯1410 2014-03-02
  • 打赏
  • 举报
回复
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<display-name></display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
我用myeslipes 开发的,这是我xml 文件,按照你说的在xml 中加入代码,显示错误啊,,望大师在看看啊,我的代码如下:
孟子E章 2014-03-01
  • 打赏
  • 举报
回复
java中文的解决方法,一般是 页面编码采用utf-8, web.xml加 <!-- 设置编码开始 --> <filter> <filter-name>Set Character Encoding</filter-name> <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> <init-param> <param-name>encoding</param-name> <param-value>UTF-8</param-value> </init-param> <init-param> <param-name>forceEncoding</param-name> <param-value>true</param-value> </init-param> </filter> <filter-mapping> <filter-name>Set Character Encoding</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <!-- 设置编码结束 --> 即可避免乱码

24,923

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 Apache
社区管理员
  • Apache
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧