分类: 系统运维
2012-03-06 19:13:31
开始需要加入jsmartcom.jar的jar包和sql server2005的驱动包
1.onselectstart属性
几乎可以用于所有对象,其触发时间为目标对象被开始选中时(即选中动作刚开始,尚未实质性被选中)。例如以下例子使得body中的内容无法被选中:
<body onselectstart="return false">
2.html中的
本元素是设置滚动文字的。例如:。其中的direction是表示移动的方向。
3.
时常用这个来写文字。
4中文乱码解决
1).在jsp中使用:
<%@ page contentType="text/html; charset=gb2312" language="java"
import="java.sql.*" errorPage=""%>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
2).在action中:
public void registerConsumer(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("gb2312");
ConsumerForm form = new ConsumerForm();
consumerDao = new ConsumerDao();
form.setAccount(Chinese.toChinese(request.getParameter("account")));
consumerDao.addConsumerForm(form)
3).DAO中:
// 添加用户信息
public boolean addConsumerForm(ConsumerForm form) {
boolean flag = false;
String sql = "insert into tb_consumer values ('" + form.getAccount()
+ "','" + form.getPassword() + "','" + form.getName() + "','"
+ form.get***() + "','" + form.getQQNumber() + "','"
+ form.getMainPage() + "','" + form.getInterest() + "','"
+ form.getEMail() + "','" + form.getManageLevel() + "')";
if (connection.executeUpdate(sql)) {
flag = true;
}
return flag;
}
3).Chinese类中:
package com.wy.tool;
public class Chinese {
public static String toChinese(String strvalue) {
try {
if (strvalue == null) {
return "";
} else {
strvalue = new String(strvalue.getBytes("ISO8859_1"), "GBK");
return strvalue;
}
} catch (Exception e) {
return "";
}
}
}
这样存入数据库中的数据便是中文了。
5.web.xml
xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
xmlns=""
xmlns:xsi=""
xsi:schemaLocation="
/web-app_2_4.xsd">
<servlet>
<description>This is the description of my J2EE componentdescription>
<display-name>This is the display name of my J2EE componentdisplay-name>
<servlet-name>ConsumerServletservlet-name>
<servlet-class>com.wy.webiter.ConsumerServletservlet-class>
servlet>
<servlet>
<description>This is the description of my J2EE componentdescription>
<display-name>This is the display name of my J2EE componentdisplay-name>
<servlet-name>FriendServletservlet-name>
<servlet-class>com.wy.webiter.FriendServletservlet-class>
servlet>
<servlet>
<description>This is the description of my J2EE componentdescription>
<display-name>This is the display name of my J2EE componentdisplay-name>
<servlet-name>VoteServletservlet-name>
<servlet-class>com.wy.webiter.VoteServletservlet-class>
servlet>
<servlet>
<description>This is the description of my J2EE componentdescription>
<display-name>This is the display name of my J2EE componentdisplay-name>
<servlet-name>DiscussServletservlet-name>
<servlet-class>com.wy.webiter.DiscussServletservlet-class>
servlet>
<servlet>
<description>This is the description of my J2EE componentdescription>
<display-name>This is the display name of my J2EE componentdisplay-name>
<servlet-name>PhotoSerlvetservlet-name>
<servlet-class>com.wy.webiter.PhotoSerlvetservlet-class>
servlet>
<servlet>
<description>This is the description of my J2EE componentdescription>
<display-name>This is the display name of my J2EE componentdisplay-name>
<servlet-name>ArticleServletservlet-name>
<servlet-class>com.wy.webiter.ArticleServletservlet-class>
servlet>
<servlet>
<description>This is the description of my J2EE componentdescription>
<display-name>This is the display name of my J2EE componentdisplay-name>
<servlet-name>RestoreServletservlet-name>
<servlet-class>com.wy.webiter.RestoreServletservlet-class>
servlet>
<servlet-mapping>
<servlet-name>ConsumerServletservlet-name>
<url-pattern>/ConsumerServleturl-pattern>
servlet-mapping>
<servlet-mapping>
<servlet-name>FriendServletservlet-name>
<url-pattern>/FriendServleturl-pattern>
servlet-mapping>
<servlet-mapping>
<servlet-name>VoteServletservlet-name>
<url-pattern>/VoteServleturl-pattern>
servlet-mapping>
<servlet-mapping>
<servlet-name>DiscussServletservlet-name>
<url-pattern>/DiscussServleturl-pattern>
servlet-mapping>
<servlet-mapping>
<servlet-name>PhotoSerlvetservlet-name>
<url-pattern>/PhotoSerlveturl-pattern>
servlet-mapping>
<servlet-mapping>
<servlet-name>ArticleServletservlet-name>
<url-pattern>/ArticleServleturl-pattern>
servlet-mapping>
<servlet-mapping>
<servlet-name>RestoreServletservlet-name>
<url-pattern>/RestoreServleturl-pattern>
servlet-mapping>
<welcome-file-list>
<welcome-file>index.jspwelcome-file>
welcome-file-list>
web-app>
6.servlet示例
public class FriendServlet extends HttpServlet {
private FriendDao friendDao = null;
private int method;
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
7.连接数据库
1).Server.properties中:
dbdriver=com.microsoft.sqlserver.jdbc.SQLServerDriver
dburl=jdbc:sqlserver://localhost:1433;DatabaseName=db_BlodMay
dbuser=sa
dbpwd=123456
2).JDBConnection类中:
package com.wy.tool;
import java.io.InputStream;
import java.sql.*;
import java.util.Properties;
//连接数据库的类
public class JDBConnection {
private static String driver = null;
private static String url = null;
private static String userName = null;
private static String password = null;
private Connection con = null;
// 通过构造方法加载数据库驱动
static {
InputStream is =JDBConnection.class.getResourceAsStream("/Server.properties");
Properties properties = new Properties();
try {
properties.load(is);
} catch (Exception ex) {
ex.printStackTrace();
throw new RuntimeException(ex.getMessage());
}
driver = properties.getProperty("dbdriver");
url = properties.getProperty("dburl");
userName = properties.getProperty("dbuser");
password = properties.getProperty("dbpwd");
try {
Class.forName(driver).newInstance();
} catch (Exception ex) {
System.out.println("数据库加载失败");
}
}
// 创建数据库连接
public boolean creatConnection() {
try {
con = DriverManager.getConnection(url, userName, password);
con.setAutoCommit(true);
} catch (SQLException e) {
System.out.println(e.getMessage());
System.out.println("creatConnectionError!");
}
return true;
}
// 对数据库的增加、修改和删除的操作
public boolean executeUpdate(String sql) {
if (con == null) {
creatConnection();
}
try {
Statement stmt = con.createStatement();
int iCount = stmt.executeUpdate(sql);
System.out.println("操作成功,所影响的记录数为" + String.valueOf(iCount));
return true;
} catch (SQLException e) {
System.out.println(e.getMessage());
return false;
}
}
// 对数据库的查询操作
public ResultSet executeQuery(String sql) {
ResultSet rs;
try {
if (con == null) {
creatConnection();
}
Statement stmt = con.createStatement();
try {
rs = stmt.executeQuery(sql);
} catch (SQLException e) {
System.out.println(e.getMessage());
return null;
}
} catch (SQLException e) {
System.out.println(e.getMessage());
System.out.println("executeQueryError!");
return null;
}
return rs;
}
}