您所在的位置:开发 > Java > Struts+hibernate开发(源代码)(1)

Struts+hibernate开发(源代码)(1)

2006-11-07 13:30 CN-JAVA 字号:T | T
一键收藏,随时查看,分享好友!

本文给出了Struts+hibernate开发的源代码。其中需要注意作者是在myeclipse环境中运行,有些运行中出现的错误,你有可能是没有加上hibernate开发包的原因。

AD:

测试页面:
index.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page language="java" import="hibernate.HibernateSessionFactory"%>
<%@ page language="java" import="mappingConfig.Admin"%>
<%@ page language="java" import="org.hibernate.HibernateException"%>
<%@ page language="java" import="org.hibernate.*"%>






username

password




right.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>


This is my JSP page.

LogAction.java
//Created by MyEclipse Struts
// XSL source (default):

platform:/plugin/com.genuitec.eclipse.cross.easystruts.eclipse_4.0.1/xslt/JavaClass.xsl

package action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import form.UserForm;
import common.Com;

/**
* MyEclipse Struts
* Creation date: 03-25-2006
*
* XDoclet definition:
* @struts.action path="/log" name="userForm" input="/index.jsp"

scope="request" validate="true"
*/
public class LogAction extends Action {

// --------------------------------------------------------- Instance Variables

// --------------------------------------------------------- Methods

/**
* Method execute
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
*/
public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) {
UserForm userForm = (UserForm) form;
// TODO Auto-generated method stub

Com.execute();
return mapping.findForward("suc");
}
}

Com.java

package common;

import hibernate.HibernateSessionFactory;
import mappingConfig.Admin;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.Transaction;

public class Com {

public static boolean execute() {

Session session;
Transaction tx = null;
try {
session = HibernateSessionFactory.currentSession();
tx = session.beginTransaction();
Admin admin = new Admin();
admin.setName("joliny");
admin.setAge("21");
admin.setEmail("jbakwd@163.com");
admin.setPassword("2466346");
admin.setSex("man");
admin.setTelphone("13571944243");
session.save(admin);
tx.commit();
} catch (HibernateException e) {
e.printStackTrace();
}
return true;
}

//public static void main(String args[]) {
//execute();
//}

}

内容导航



分享到:

  1. 程序员面试失败的几种原因,你中枪了吗?
  2. Java未来也许不再是电商的首选开发语言!

热点职位

更多>>

热点专题

更多>>

读书

XML案例解析教程
本书对开发XML应用程序给予了详细指导,其中一些应用程序甚至对于您来说是完全陌生的。这些应用程序包括XML 1.0,以及与XSLT、XQ

51CTO旗下网站

领先的IT技术网站 51CTO 领先的中文存储媒体 WatchStor 中国首个CIO网站 CIOage 中国首家数字医疗网站 HC3i 51CTO学院