日期:2014-05-17  浏览次数:20599 次

SSH整合例子(仅用到ss处理登录demo)出现异常
帖代码先
---------------------------------
public class User { // 实体类

private String name;
private String password;
//省略set get方法

----------------------------------
public interface IUserService {// 接口

boolean login(User user);
boolean register(User user);
}
------------------------------------//接口实现类
public class UserService implements IUserService {
public boolean login(User user){
 
if("user".equals(user.getName())&&"user".equals(user.getPassword()))
{
return true;
}else{
return false;
}
}
public boolean register(User user){
  
if("qqq".equals(user.getName())&&"qqq".equals(user.getPassword())){
return true;
}else{
return false;}
}
}
------------------------
//action
package com.action;

import com.opensymphony.xwork2.ActionSupport;
import com.service.IUserService;
import com.vo.User;

public class UserAction extends ActionSupport {

/**
*  
*/
private static final long serialVersionUID = 1L;
private User user = new User();
private IUserService service;
 
 
public User getUser() {
return user;
}

public void setUser(User user) {
this.user = user;
}

public IUserService getService() {
return service;
}

public void setService(IUserService service) {
this.service = service;
}

public String login(){
System.out.println(getService());
System.out.println(user.getName());
if(service.login(user)){
return SUCCESS;
}else{
return ERROR;
}
}

  public String register(){
  System.out.println(user.getName());
if(service.register(user)){
return SUCCESS;
}else{
return ERROR;
}


}
 
}
-----------------------------------------------------下面的所有配置文件
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">
<context-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>classpath*:applicationContext.xml</param-value>
  </context-param>
  <listener>
  <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
  <welcome-file-list>
  <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
  
  <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></web-app>
-------------------------
struts.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" " http://struts.apache.org/dtds/struts-2.1.dtd">
<struts&g