生成用户表:
create table t_user(
user_id int auto_increment not null,
username varchar(10) not null,
password varchar(15) not null,
email varchar(20) ,
is_webmaster char(1) not null default '0',
is_administrator char(1) not null default '0',
primary key (user_id),
UNIQUE KEY user (username)
)ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
insert into t_user(username,password,email) values('limx','limx','lovelimx@sina.com');
insert into t_user(username,password,email) values('messi','messi','lovemessi@sina.com');
工程web.xml配置文件:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
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_2_5.xsd">
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
struts.xml配置文件:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="user" namespace="" extends="struts-default">
<action name="register" class="bbs.action.RegisterAction">
<result name="success">jsp/user/login.jsp</result>
<result name="input">jsp/user/register.jsp
</result>
</action>
</package>
</struts>
applicationContext.xml配置文件:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<bean id="DataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver">
</property>
<property name="url" value="jdbc:mysql://localhost:3306/forum">
</property>
<property name="username" value="root"></property>
<property name="password" value="limx"></property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="DataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>forum/model/TUser.hbm.xml</value>
</list>
</property>
</bean>
<bean id="TUserDAO" class="forum.dao.TUserDAO">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
</beans>
TUser.hbm.xml配置文件:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!--
Mapping file autogenerated by MyEclipse Persistence Tools
-->
<hibernate-mapping>
<class name="forum.model.TUser" table="t_user" catalog="forum">
<id name="userId" type="java.lang.Integer">
<column name="user_id" />
<generator class="identity" />
</id>
<property name="username" type="java.lang.String">
<column name="username" length="10" not-null="true" unique="true" />
</property>
<property name="password" type="java.lang.String">
<column name="password" length="15" not-null="true" />
</property>
<property name="email" type="java.lang.String">
<column name="email" length="20" />
</property>
<property name="isWebmaster" type="java.lang.String">
<column name="is_webmaster" length="1" not-null="true" />
</property>
<property name="isAdministrator" type="java.lang.String">
<column name="is_administrator" length="1" not-null="true" />
</property>
</class>
</hibernate-mapping>
TUser.java
package forum.model;
import java.util.HashSet;
import java.util.Set;
/**
* TUser entity. @author MyEclipse Persistence Tools
*/
public class TUser implements java.io.Serializable {
// Fields
private Integer userId;
private String username;
private String password;
private String email;
private String isWebmaster;
private String isAdministrator;
// Constructors
/** default constructor */
public TUser() {
}
/** minimal constructor */
public TUser(String username, String password, String isWebmaster,
String isAdministrator) {
this.username = username;
this.password = password;
this.isWebmaster = isWebmaster;
this.isAdministrator = isAdministrator;
}
/** full constructor */
public TUser(String username, String password, String email,
String isWebmaster, String isAdministrator) {
this.username = username;
this.password = password;
this.email = email;
this.isWebmaster = isWebmaster;
this.isAdministrator = isAdministrator;
}
// Property accessors
public Integer getUserId() {
return this.userId;
}
public void setUserId(Integer userId) {
this.userId = userId;
}
public String getUsername() {
return this.username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return this.password;
}
public void setPassword(String password) {
this.password = password;
}
public String getEmail() {
return this.email;
}
public void setEmail(String email) {
this.email = email;
}
public String getIsWebmaster() {
return this.isWebmaster;
}
public void setIsWebmaster(String isWebmaster) {
this.isWebmaster = isWebmaster;
}
public String getIsAdministrator() {
return this.isAdministrator;
}
public void setIsAdministrator(String isAdministrator) {
this.isAdministrator = isAdministrator;
}
}
RegisterAction.java
package bbs.action;
import forum.dao.TUserDAO;
import forum.model.*;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
public class RegisterAction extends ActionSupport implements ModelDriven {
private TUser user = new TUser();
public Object getModel() {
return user;
}
public String execute() {
// TUserDAO userDAO = new TUserDAO();
// suserDAO.save(user);
ApplicationContext context = new ClassPathXmlApplicationContext(
"applicationContext.xml");
TUserDAO dao = (TUserDAO) context.getBean("TUserDAO");
try {
dao.save(user);
} catch (Exception e) {
return INPUT;
}
return SUCCESS;
}
}
Register.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%
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 'register.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>
<form action="register" method="post">
<s:textfield label="username" name="username" value="" ></s:textfield><br>
<s:password label="password" name="password" value="">
</s:password><br>
<s:textfield label="email" name="email" value="">
</s:textfield><br>
<s:submit value="register" align="left"></s:submit>
</form>
</body>
</html>
ps:因为是从工程里面拿出来修改的,所以有可能出现错误,需要工程源码的话,再找我要;
分享到:
相关推荐
maven3+struts2+spring+ibatis,本来是用maven3+struts2+spring+hibernate但考虑到hibernate在多表级联查询的时候执行效率不高,所以改用性能更好不过sql比较麻烦的的ibatis,本项目只有登录和插入数据,仅供参考: ...
所以没有上传导入的jar,其实就是默认的struts2和hibernate以及spring的包.该项目使用的jar包为以下. spring-beans.jar xwork-2.0.4.jar spring-context.jar ognl-2.6.11.jar spring-web.jar ...
用SSH做的简易论坛系统,功能算丰富,CRUD,...开始先要对板块插入数据,表可以用hibernate的自动创建,hibernate和spring用的都是注解技术,dao层用了江南白衣的思想,已封装,测试过,我没发现bug,希望对你有所帮助
这是一个简单的登录和数据插入的项目,因为是实际项目,里面有些代码是冗余的,用到的表只有push_message和EDITOR_INFO两个 开发中遇到两个问题: 1.STRUTS2乱码,解决方法是在struts.xml中加入 <constant name="...
它完全支持结构化查询语言(SQL),允许用户进行数据查询、插入、更新、删除、创建和管理数据库结构等操作。SQL标准的广泛支持使得MySQL易于学习,且与其他关系型数据库系统有良好的互操作性。 存储引擎 MySQL支持...
主要的功能有: 用户登录 对图书的增删改查搜索分页 使用的数据库为mysql ...6.将hibernate.hbm2ddl.auto的值改为update,这样重新启动项目就不会重新创建表 整体的功能实现,没有表单的验证。美观程度一般。
StrutsHibernateBySQLImplTest.java :为单元测试类 自动生成表:具体数据库 sqlserver2000 ,oracle 服务层代码如下: ...此时如果插入sqlserver的数据太大,则回滚: 都插不进去 测试通过的例子:
运行博客推荐程序需要注意的地方: 1. 打开mysql,增加blog数据库;... 2. 修改blog.xml(和Readme.txt同目录)的docBase为本地目录,放在tomcat的conf\...版本:Spring3+Struts2+Hibernate3+Hadoop1.0.4+Mahout0.7+Mysql5
SSH框架 struts2 +spring +hibernate mysql数据库 myeclipse开发 系统介绍:分为这5个大模块 系统设置 整车销售 辅助销售 汽修管理 汽修统计 系统设置大模块: 1.经理管理 (增加 和删除功能) 表设计...
采用ssh(spring+Struts2+hibernate)技术开发的oa管理项目.有增删改查等基本功能,分页模板,部署工作了.完整的项目资源,采用了hibernate的注解功能可以直接生成数据库表,需要更改jdbc.properties就可以运行项目了.不过...
☆ Spring ORM:Spring 框架插入了若干个 ORM 框架,从而提供了 ORM 的对象关系工具,其中包括 JDO、Hibernate 和 iBatis SQL Map。所有这些都遵从 Spring 的通用事务和 DAO 异常层次结构。 ☆ Spring Web 模块:...
2. Spring 2.0 的新特性 2.1. 简介 2.2. 控制反转(IoC)容器 2.2.1. 更简单的XML配置 2.2.2. 新的bean作用域 2.2.3. 可扩展的XML编写 2.3. 面向切面编程(AOP) 2.3.1. 更加简单的AOP XML配置 2.3.2. 对@...
2. Spring 2.0 的新特性 2.1. 简介 2.2. 控制反转(IoC)容器 2.2.1. 更简单的XML配置 2.2.2. 新的bean作用域 2.2.3. 可扩展的XML编写 2.3. 面向切面编程(AOP) 2.3.1. 更加简单的AOP XML配置 2.3.2. 对@AspectJ 切面的...
求解。。如何使用 struts spring hibernate多表插入数据!我在类型那里傻了。。菜鸟求解!
11.5.1. 使用SimpleJdbcInsert插入数据 11.5.2. 使用SimpleJdbcInsert来获取自动生成的主键 11.5.3. 指定SimpleJdbcInsert所使用的字段 11.5.4. 使用SqlParameterSource提供参数值 11.5.5. 使用SimpleJdbcCall...
2. Spring 2.0 的新特性 2.1. 简介 2.2. 控制反转(IoC)容器 2.2.1. 更简单的XML配置 2.2.2. 新的bean作用域 2.2.3. 可扩展的XML编写 2.3. 面向切面编程(AOP) 2.3.1. 更加简单的AOP XML配置 2.3.2. 对@...
11.5.1. 使用SimpleJdbcInsert插入数据 11.5.2. 使用SimpleJdbcInsert来获取自动生成的主键 11.5.3. 指定SimpleJdbcInsert所使用的字段 11.5.4. 使用SqlParameterSource提供参数值 11.5.5. 使用SimpleJdbcCall...
struts2 的 Action 使用 spring 注解,被 spring 管理 @Controller spring 表现层 bean @Scope 配置 Action 为多例 Spring Data JPA 代替了 Hibernate "CURD " 但是和Hibernate一样 实现DAO(数据)层的功能 "增...
以及基于这些技术的商业化应用程序的开发技巧,在讲解过程中以目前最为流行的开发工具MyEclipse为载体,全面系统地介绍了如何在MyEclipse中开发基于Struts、Hibernate、Spring等主流框架的各种Java应用程序。...
\contentsline {chapter}{Contents}{2}{section*.1} {1}Java基础}{17}{chapter.1} {1.1}基本语法}{17}{section.1.1} {1.2}数字表达方式}{17}{section.1.2} {1.3}补码}{19}{section.1.3} {1.3.1}总结}{23}{...