首页

Java Struts+Spring+Hibernate SSH框架实例源码(含数据库脚本)

java

2020-8-19

下载地址

本实例SSH版本 Struts2.3.16 Spring4.1.1  Hibernate4.3.6

首先你要创建mysql 或者 oracle数据库(doc目录下有),

然后你需要修改src/jdbc.properties 文件中的数据库配置串

然后即可浏览程序

常见的问题 tomcat版本不一致,jre版本不一致 提示 unbound,修改方法 点击这里查看

package com.xmm.demo.action;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.ExceptionMapping;
import org.apache.struts2.convention.annotation.ExceptionMappings;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.stereotype.Controller;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.opensymphony.xwork2.ActionSupport;
import com.xmm.demo.domain.Emp;
import com.xmm.demo.service.EmpService;

@Controller
@ParentPackage("struts-default") 
@Namespace(value = "/loginAction")
@ExceptionMappings({ @ExceptionMapping(exception = "java.lange.RuntimeException", result = "error") })  
public class LoginAction extends ActionSupport {

	private static final long serialVersionUID = 1L;

	@Resource
	private EmpService empService;

	private String empname;
	private String password;

	@Action(value = "login" , results = { @Result(name = "success", location = "/success.jsp"),
				@Result(name = "failure", location = "/failure.jsp"),
				@Result(name = "error", location = "/login.jsp")})
	public String login() {

		System.out.println("\n提交的请求参数如下:");
		System.out.println("empname:"   empname);
		System.out.println("password:"   password   "\n");

		int eid = 0;
		try {
			eid = Integer.parseInt(empname);
		} catch (Exception ex) {
		}

		Emp emp = empService.findEmpById(eid);// 为了测试结果,这里写死了
		//List<Emp>listemp=empService.findAllList();
		if (emp != null) {
			System.out.println("\n根据主键ID查询记录:查到了,查询成功!");
			System.out.println(emp.toString()   "\n");

			HttpServletRequest request = ServletActionContext.getRequest();// 在Struts2的Action中获取Servlet的原生API
			request.setAttribute("empname", emp.getEname());

			// 注意:这里使用GsonBuilder来创建Gson实例
			Gson gson = new GsonBuilder().setPrettyPrinting().setDateFormat("yyyy-MM-dd HH:mm:ss:SSS").create();
			String empJson = gson.toJson(emp);
			System.out.println("\nEmp对象转化为JSON格式:");
			System.out.println(empJson   "\n");

			return SUCCESS;
		} else {
			System.out.println("\n根据主键ID查询记录:没查到,查询失败,记录不存在!\n");
			return "failure";
		}

	}

	public String getEmpname() {
		return empname;
	}

	public void setEmpname(String empname) {
		this.empname = empname;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

}
资源下载此资源下载价格为3D币,请先

资源文件列表

.project , 1340
.settings/.jsdtscope , 522
.settings/com.genuitec.eclipse.j2eedt.core.prefs , 1009
.settings/org.eclipse.core.resources.prefs , 57
.settings/org.eclipse.jdt.core.prefs , 598
.settings/org.eclipse.wst.common.component , 572
.settings/org.eclipse.wst.common.project.facet.core.xml , 398
.settings/org.eclipse.wst.jsdt.ui.superType.container , 49
.settings/org.eclipse.wst.jsdt.ui.superType.name , 6
doc/db_mysql.sql , 3730
doc/db_oracle.sql , 3647
doc/readme.txt , 1117
src/applicationContext-quartz.xml , 3315
src/applicationContext.xml , 9164
src/com/xmm/demo/action/LoginAction.java , 2911
src/com/xmm/demo/dao/BaseDAO.java , 2711
src/com/xmm/demo/dao/impl/BaseDAOImpl.java , 4519
src/com/xmm/demo/domain/Customer.java , 1421
src/com/xmm/demo/domain/Emp.java , 2512
src/com/xmm/demo/domain/Order.java , 1551
src/com/xmm/demo/filter/CharacterEncodingFilter.java , 1899
src/com/xmm/demo/filter/ClientNoCacheFilter.java , 2132
src/com/xmm/demo/filter/PageEhCacheFilter.java , 3853
src/com/xmm/demo/interceptor/MethodCacheInterceptor.java , 2978
src/com/xmm/demo/quartz/FirstQuartz.java , 281
src/com/xmm/demo/service/EmpService.java , 306
src/com/xmm/demo/service/imp/EmpServiceImpl.java , 894
src/com/xmm/demo/util/HibernateUtils.java , 1274
src/ehcache.xml , 2968
src/jdbc.properties , 1946
src/log4j.properties , 7433
src/struts.xml , 1990
WebRoot/error/error.jsp , 388
WebRoot/error/error404.jsp , 336
WebRoot/error/error500.jsp , 336
WebRoot/error/exceptionPage.jsp , 439
WebRoot/error/loginError.jsp , 378
WebRoot/failure.jsp , 701
WebRoot/index.jsp , 774
WebRoot/js/jquery/jquery-1.11.1.js , 282766
WebRoot/js/jquery/jquery-1.11.1.min.js , 95786
WebRoot/js/jquery/jquery-2.1.1.js , 247351
WebRoot/js/jquery/jquery-2.1.1.min.js , 84245
WebRoot/js/jquery/readme.txt , 281
WebRoot/js/mystring.js , 12915
WebRoot/login.jsp , 908
WebRoot/META-INF/MANIFEST.MF , 39
WebRoot/success.jsp , 648
WebRoot/WEB-INF/classes/applicationContext-quartz.xml , 3315
WebRoot/WEB-INF/classes/applicationContext.xml , 9164
WebRoot/WEB-INF/classes/com/xmm/demo/action/LoginAction.class , 3618
WebRoot/WEB-INF/classes/com/xmm/demo/dao/BaseDAO.class , 2164
WebRoot/WEB-INF/classes/com/xmm/demo/dao/impl/BaseDAOImpl.class , 7243
WebRoot/WEB-INF/classes/com/xmm/demo/domain/Customer.class , 2097
WebRoot/WEB-INF/classes/com/xmm/demo/domain/Emp.class , 3316
WebRoot/WEB-INF/classes/com/xmm/demo/domain/Order.class , 1826
WebRoot/WEB-INF/classes/com/xmm/demo/filter/CharacterEncodingFilter.class , 2416
WebRoot/WEB-INF/classes/com/xmm/demo/filter/ClientNoCacheFilter.class , 2444
WebRoot/WEB-INF/classes/com/xmm/demo/filter/PageEhCacheFilter.class , 4279
WebRoot/WEB-INF/classes/com/xmm/demo/interceptor/MethodCacheInterceptor.class , 3278
WebRoot/WEB-INF/classes/com/xmm/demo/quartz/FirstQuartz.class , 881
WebRoot/WEB-INF/classes/com/xmm/demo/service/EmpService.class , 375
WebRoot/WEB-INF/classes/com/xmm/demo/service/imp/EmpServiceImpl.class , 1745
WebRoot/WEB-INF/classes/com/xmm/demo/util/HibernateUtils.class , 1425
WebRoot/WEB-INF/classes/ehcache.xml , 2968
WebRoot/WEB-INF/classes/jdbc.properties , 1946
WebRoot/WEB-INF/classes/log4j.properties , 7433
WebRoot/WEB-INF/classes/struts.xml , 1990
WebRoot/WEB-INF/lib/antlr-2.7.7.jar , 445288
WebRoot/WEB-INF/lib/aopalliance-1.0.jar , 4467
WebRoot/WEB-INF/lib/asm-3.3.jar , 43578
WebRoot/WEB-INF/lib/asm-commons-3.3.jar , 38275
WebRoot/WEB-INF/lib/aspectjweaver-1.8.2.jar , 1859293
WebRoot/WEB-INF/lib/c3p0-0.9.2.1.jar , 423876
WebRoot/WEB-INF/lib/commons-beanutils-1.8.0.jar , 231320
WebRoot/WEB-INF/lib/commons-collections-3.1.jar , 559366
WebRoot/WEB-INF/lib/commons-dbcp-1.4.jar , 160519
WebRoot/WEB-INF/lib/commons-fileupload-1.3.1.jar , 69002
WebRoot/WEB-INF/lib/commons-io-2.2.jar , 173587
WebRoot/WEB-INF/lib/commons-lang-2.4.jar , 261809
WebRoot/WEB-INF/lib/commons-lang3-3.1.jar , 315805
WebRoot/WEB-INF/lib/commons-logging-1.1.3.jar , 62050
WebRoot/WEB-INF/lib/commons-pool-1.6.jar , 111119
WebRoot/WEB-INF/lib/dom4j-1.6.1.jar , 313898
WebRoot/WEB-INF/lib/ehcache-2.8.3.jar , 5637564
WebRoot/WEB-INF/lib/ehcache-core-2.4.3.jar , 1006424
WebRoot/WEB-INF/lib/ehcache-web-2.0.4.jar , 44842
WebRoot/WEB-INF/lib/ezmorph-1.0.6.jar , 86487
WebRoot/WEB-INF/lib/freemarker-2.3.19.jar , 931168
WebRoot/WEB-INF/lib/gson-2.2.4.jar , 190418
WebRoot/WEB-INF/lib/hamcrest-core-1.3.jar , 45024
WebRoot/WEB-INF/lib/hibernate-c3p0-4.3.6.Final.jar , 40140
WebRoot/WEB-INF/lib/hibernate-commons-annotations-4.0.5.Final.jar , 75324
WebRoot/WEB-INF/lib/hibernate-core-4.3.6.Final.jar , 5254140
WebRoot/WEB-INF/lib/hibernate-ehcache-4.3.6.Final.jar , 135516
WebRoot/WEB-INF/lib/hibernate-jpa-2.1-api-1.0.0.Final.jar , 113371
WebRoot/WEB-INF/lib/jandex-1.1.0.Final.jar , 76551
WebRoot/WEB-INF/lib/javassist-3.11.0.GA.jar , 614203
WebRoot/WEB-INF/lib/javassist-3.18.1-GA.jar , 714194
WebRoot/WEB-INF/lib/jboss-logging-3.1.3.GA.jar , 57183
WebRoot/WEB-INF/lib/jboss-logging-annotations-1.2.0.Beta1.jar , 11558
WebRoot/WEB-INF/lib/jboss-transaction-api_1.2_spec-1.0.0.Final.jar , 27717
WebRoot/WEB-INF/lib/jstl-1.2_1.jar , 441042
WebRoot/WEB-INF/lib/junit-4.11.jar , 245039
WebRoot/WEB-INF/lib/junit-4.9.jar , 253724
WebRoot/WEB-INF/lib/log4j-1.2.17.jar , 489884
WebRoot/WEB-INF/lib/mchange-commons-java-0.2.3.4.jar , 581295
WebRoot/WEB-INF/lib/mysql-5.0.5.jar , 512707
WebRoot/WEB-INF/lib/ognl-3.0.6.jar , 227997
WebRoot/WEB-INF/lib/ojdbc14.jar , 1536554
WebRoot/WEB-INF/lib/quartz-2.2.1.jar , 660324
WebRoot/WEB-INF/lib/quartz-jobs-2.2.1.jar , 33979
WebRoot/WEB-INF/lib/readme.txt , 1122
WebRoot/WEB-INF/lib/slf4j-api-1.6.1.jar , 25496
WebRoot/WEB-INF/lib/slf4j-api-1.7.7.jar , 29257
WebRoot/WEB-INF/lib/slf4j-log4j12-1.7.7.jar , 8870
WebRoot/WEB-INF/lib/spring-aop-4.1.1.RELEASE.jar , 359023
WebRoot/WEB-INF/lib/spring-aspects-4.1.1.RELEASE.jar , 56510
WebRoot/WEB-INF/lib/spring-beans-4.1.1.RELEASE.jar , 703685
WebRoot/WEB-INF/lib/spring-context-4.1.1.RELEASE.jar , 1026617
WebRoot/WEB-INF/lib/spring-context-support-4.1.1.RELEASE.jar , 177246
WebRoot/WEB-INF/lib/spring-core-4.1.1.RELEASE.jar , 1004360
WebRoot/WEB-INF/lib/spring-expression-4.1.1.RELEASE.jar , 249660
WebRoot/WEB-INF/lib/spring-jdbc-4.1.1.RELEASE.jar , 428320
WebRoot/WEB-INF/lib/spring-orm-4.1.1.RELEASE.jar , 373799
WebRoot/WEB-INF/lib/spring-test-4.1.1.RELEASE.jar , 501832
WebRoot/WEB-INF/lib/spring-tx-4.1.1.RELEASE.jar , 252352
WebRoot/WEB-INF/lib/spring-web-4.1.1.RELEASE.jar , 700044
WebRoot/WEB-INF/lib/spring-webmvc-4.1.1.RELEASE.jar , 775353
WebRoot/WEB-INF/lib/sqljdbc4.jar , 584207
WebRoot/WEB-INF/lib/struts2-convention-plugin-2.3.16.1.jar , 67159
WebRoot/WEB-INF/lib/struts2-core-2.3.16.3.jar , 800691
WebRoot/WEB-INF/lib/struts2-spring-plugin-2.3.16.3.jar , 21659
WebRoot/WEB-INF/lib/testng-6.8.8.jar , 836479
WebRoot/WEB-INF/lib/xwork-core-2.3.16.3.jar , 654177
WebRoot/WEB-INF/web.xml , 2731
没有账号? 忘记密码?

社交账号快速登录