我现在学习ssh,做了个简单的选课系统,遇到个问题请教大家:
1、情况是这样,在返回所有student的页面,我通过id调用一个selectCourseAction1,在这个action中我通过id获得student对象并放到session中,然后重定向到返回所有课程的action中,执行成功到列出所有课程的页面,在这个页面通过课程id再调用selectCourseAction2,在这个action中,我首先通过id获得课程对象,然后再获取存在session中student对象,然后执行相应的存储。2、现在的问题是,并不报错,可是数据库中并没有存储结果,我想问的是这样传递student对象能行吗,?
 下面是我最后的selectCourseAction2代码package com.test.action;import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.test.bean.Course;
import com.test.bean.Student;
import com.test.dao.CourseDao;
import com.test.dao.StudentDao;public class SelectCourseAction2 extends ActionSupport
{
private String id;
private StudentDao studentDao;
private CourseDao courseDao; public String getId()
{
return id;
} public void setId(String id)
{
this.id = id;
} public StudentDao getStudentDao()
{
return studentDao;
} public void setStudentDao(StudentDao studentDao)
{
this.studentDao = studentDao;
} public CourseDao getCourseDao()
{
return courseDao;
} public void setCourseDao(CourseDao courseDao)
{
this.courseDao = courseDao;
} @Override
public String execute() throws Exception
{ Course course = this.courseDao.findCourseById(id); Student student = (Student) ActionContext.getContext().getSession()
.get("student"); course.getStudents().add(student);
student.getCourses().add(course);
this.studentDao.saveOrupdate(student);
return SUCCESS; }}

解决方案 »

  1.   

    没看明白
    把操作都放到一个action里处理
      

  2.   

    我没有做登陆的模块,只有列出所有学生、课程的页面,放到一个action里面,我不知道如何把学生、课程对象同时取出来。我上面说的做法就是先从列出所有学生的页面通过id获得学生对象放到session中,然后在列出所有课程的页面通过课程id取出课程对象,然后相互存进去,但结果没有存进去