请问EJB3.0和STRUTS2.0整合的问题,谢谢了

lj13052615595 2008-04-21 02:48:58
我的程序好像始终跑不起来,报错有时候是404,有时候是500.帮我看看怎么回事吧。
运行环境是NetBeans 加 GlassFish V2 JDK 是1.5的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>

<!-- Add packages here -->
<include file="struts-default.xml" />

<package name="emp.Action" extends="struts-default">
<action name="AddEmp" class="emp.Action.AddEmpAction">
<result name="ok">/checkOver.jsp </result>
<result name="fault">/checkError.jsp </result>
</action>
</package>

</struts>

EJB的bean

package emp.Interface;

import emp.FormBean.EmpInfo;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
*
* @author liuaichang
*/
@Stateless
public class AddEmpServiceBean implements AddEmpService{
private Date workStart;
private Date birth;
private SimpleDateFormat sd;

@PersistenceContext(unitName = "AddEmpService")
protected EntityManager em;


public EntityManager getEntityManager() {
return em;
}


public int addEmpInfo(String empId, String familyName, String firstName, String sex, String birthday, String address, String phoneNumber, String mobile, String faxNumber, String email, String offName, String occupation, String workStartDate) {
sd=new java.text.SimpleDateFormat("yyyy/MM/dd");
try {
birth = sd.parse(birthday);
} catch (ParseException ex) {
Logger.getLogger(AddEmpServiceBean.class.getName()).log(Level.SEVERE, null, ex);
}
try {
workStart = sd.parse(workStartDate);
} catch (ParseException ex) {
Logger.getLogger(AddEmpServiceBean.class.getName()).log(Level.SEVERE, null, ex);
}
EmpInfo emp1=new EmpInfo(empId);
System.out.println(birth);
System.out.println(workStart);
emp1.setAddress(address);
emp1.setBirthday(birth);
emp1.setEmail(email);
emp1.setFamilyName(familyName);
emp1.setFaxNumber(faxNumber);
emp1.setFirstName(firstName);
emp1.setMobile(mobile);
emp1.setOccupation(occupation);
emp1.setOffName(offName);
emp1.setPhoneNumber(phoneNumber);
emp1.setSex(sex);
emp1.setWorkStartDate(workStart);
em.persist(emp1);

return 1;
}

}


action:
package emp.Action;

import emp.Interface.AddEmpService;
import javax.ejb.EJB;

/**
*
* @author liuaichang
*/

public class AddEmpAction {

@EJB AddEmpService service;

private String empId;
private String sex;
private String familyName;
private String firstName;
private String email;
private String mobile;
private String offName;
private String occupation;
private String year1;
private String month1;
private String day1;
private String year2;
private String month;
private String day;
private String adress;
private String faxNumber;
private String phoneNumber;

public String getAdress() {
return adress;
}

public String getDay() {
return day;
}

public String getDay1() {
return day1;
}

public String getEmail() {
return email;
}

public String getEmpId() {
return empId;
}

public String getFamilyName() {
return familyName;
}

public String getFaxNumber() {
return faxNumber;
}

public String getFirstName() {
return firstName;
}

public String getMobile() {
return mobile;
}

public String getMonth() {
return month;
}

public String getMonth1() {
return month1;
}

public String getOccupation() {
return occupation;
}

public String getOffName() {
return offName;
}

public String getPhoneNumber() {
return phoneNumber;
}

public String getSex() {
return sex;
}

public String getYear1() {
return year1;
}

public String getYear2() {
return year2;
}

public void setAdress(String adress) {
this.adress = adress;
}

public void setDay(String day) {
this.day = day;
}

public void setDay1(String day1) {
this.day1 = day1;
}

public void setEmail(String email) {
this.email = email;
}

public void setEmpId(String empId) {
this.empId = empId;
}

public void setFamilyName(String familyName) {
this.familyName = familyName;
}

public void setFaxNumber(String faxNumber) {
this.faxNumber = faxNumber;
}

public void setFirstName(String firstName) {
this.firstName = firstName;
}

public void setMobile(String mobile) {
this.mobile = mobile;
}

public void setMonth(String month) {
this.month = month;
}

public void setMonth1(String month1) {
this.month1 = month1;
}

public void setOccupation(String occupation) {
this.occupation = occupation;
}

public void setOffName(String offName) {
this.offName = offName;
}

public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}

public void setSex(String sex) {
this.sex = sex;
}

public void setYear1(String year1) {
this.year1 = year1;
}

public void setYear2(String year2) {
this.year2 = year2;
}

public String execute() throws Exception
{
String a=getMonth1();
String b=getDay1();
String x=getMonth();
String y=getDay();

if (a.length() < 2){
a = "0" + a;
}

if (b.length() < 2)
{
b = "0" + b;
}

if (x.length() < 2)
{
x = "0" + x;
}

if (y.length() < 2)
{
y = "0" + y;
}

String birthday=getYear1()+"/"+a+"/"+b;
String workStartDate=getYear2()+"/"+x+"/"+y;
if(service.addEmpInfo(getEmpId(), getFamilyName(), getFirstName(), getSex(), birthday, getAdress(), getPhoneNumber(), getMobile(), getFaxNumber(), getEmail(),getOffName(), getOccupation(), workStartDate) == 1){

return "ok";
}

return "fault";
}

}
...全文
172 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
jdlsfl 2008-07-25
  • 打赏
  • 举报
回复
up
lj13052615595 2008-04-22
  • 打赏
  • 举报
回复
定上去,那位能告诉我啊
lj13052615595 2008-04-21
  • 打赏
  • 举报
回复
action是:

/*
* To change this template, choose Tools ¦ Templates
* and open the template in the editor.
*/

package emp.Action;

import emp.Interface.AddEmpService;
import javax.ejb.EJB;

/**
*
* @author liuaichang
*/

public class AddEmpAction {

@EJB AddEmpService service;

private String empId;
private String sex;
private String familyName;
private String firstName;
private String email;
private String mobile;
private String offName;
private String occupation;
private String year1;
private String month1;
private String day1;
private String year2;
private String month;
private String day;
private String adress;
private String faxNumber;
private String phoneNumber;

public String getAdress() {
return adress;
}

public String getDay() {
return day;
}

public String getDay1() {
return day1;
}

public String getEmail() {
return email;
}

public String getEmpId() {
return empId;
}

public String getFamilyName() {
return familyName;
}

public String getFaxNumber() {
return faxNumber;
}

public String getFirstName() {
return firstName;
}

public String getMobile() {
return mobile;
}

public String getMonth() {
return month;
}

public String getMonth1() {
return month1;
}

public String getOccupation() {
return occupation;
}

public String getOffName() {
return offName;
}

public String getPhoneNumber() {
return phoneNumber;
}

public String getSex() {
return sex;
}

public String getYear1() {
return year1;
}

public String getYear2() {
return year2;
}

public void setAdress(String adress) {
this.adress = adress;
}

public void setDay(String day) {
this.day = day;
}

public void setDay1(String day1) {
this.day1 = day1;
}

public void setEmail(String email) {
this.email = email;
}

public void setEmpId(String empId) {
this.empId = empId;
}

public void setFamilyName(String familyName) {
this.familyName = familyName;
}

public void setFaxNumber(String faxNumber) {
this.faxNumber = faxNumber;
}

public void setFirstName(String firstName) {
this.firstName = firstName;
}

public void setMobile(String mobile) {
this.mobile = mobile;
}

public void setMonth(String month) {
this.month = month;
}

public void setMonth1(String month1) {
this.month1 = month1;
}

public void setOccupation(String occupation) {
this.occupation = occupation;
}

public void setOffName(String offName) {
this.offName = offName;
}

public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}

public void setSex(String sex) {
this.sex = sex;
}

public void setYear1(String year1) {
this.year1 = year1;
}

public void setYear2(String year2) {
this.year2 = year2;
}

public String execute() throws Exception
{
String a=getMonth1();
String b=getDay1();
String x=getMonth();
String y=getDay();

if (a.length() < 2){
a = "0" + a;
}

if (b.length() < 2)
{
b = "0" + b;
}

if (x.length() < 2)
{
x = "0" + x;
}

if (y.length() < 2)
{
y = "0" + y;
}

String birthday=getYear1()+"/"+a+"/"+b;
String workStartDate=getYear2()+"/"+x+"/"+y;
if(service.addEmpInfo(getEmpId(), getFamilyName(), getFirstName(), getSex(), birthday, getAdress(), getPhoneNumber(), getMobile(), getFaxNumber(), getEmail(),getOffName(), getOccupation(), workStartDate) == 1){

return "ok";
}

return "fault";
}

}
lj13052615595 2008-04-21
  • 打赏
  • 举报
回复

}

/**
* @param address the address to set
*/
public void setAddress(String address) {
this.address = address;
}

/**
* @return the phoneNumber
*/
public String getPhoneNumber() {
return phoneNumber;
}

/**
* @param phoneNumber the phoneNumber to set
*/
public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}

/**
* @return the mobile
*/
public String getMobile() {
return mobile;
}

/**
* @param mobile the mobile to set
*/
public void setMobile(String mobile) {
this.mobile = mobile;
}

/**
* @return the faxNumber
*/
public String getFaxNumber() {
return faxNumber;
}

/**
* @param faxNumber the faxNumber to set
*/
public void setFaxNumber(String faxNumber) {
this.faxNumber = faxNumber;
}

/**
* @return the email
*/
public String getEmail() {
return email;
}

/**
* @param email the email to set
*/
public void setEmail(String email) {
this.email = email;
}

/**
* @return the offName
*/
public String getOffName() {
return offName;
}

/**
* @param offName the offName to set
*/
public void setOffName(String offName) {
this.offName = offName;
}

/**
* @return the occupation
*/
public String getOccupation() {
return occupation;
}

/**
* @param occupation the occupation to set
*/
public void setOccupation(String occupation) {
this.occupation = occupation;
}

/**
* @return the workStartDate
*/
public Date getWorkStartDate() {
return workStartDate;
}

/**
* @param workStartDate the workStartDate to set
*/
public void setWorkStartDate(Date workStart) {
this.workStartDate = workStart;
}
}

JSP 的 部分提交代码是:

<s:form name="form1" action="AddEmp.action">


function choose2() {
form1.action="AddEmp";
form1.target="main"
form1.submit();
}


<INPUT name="save" type=button id="save" value=" 保存 " onclick="choose2()">

62,623

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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