strut.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> <constant name="struts.enable.DynamicMethodInvocation" value="true" /> <package name="web" extends="struts-default" namespace="">
<default-interceptor-ref name="paramsPrepareParamsStack" />
<!--登录管理 -->
<action name="login"
class="com.talkweb.web.action.LoginAction">
<result name="success">/admin/index.jsp</result>
<result name="failure">/index.jsp</result>
<result name="loginOut">/index.jsp</result>
</action> </package></struts>aplicationcontext.xml
?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"> <bean id = "StudentAdminImpl" class="com.talkweb.service.impl.StudentAdminImpl"></bean> <bean id="loginAction" class="com.talkweb.web.action.LoginAction" >
<property name="adminService" ref="StudentAdminImpl" />
</bean></beans>web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> <!-- Struts2 filter,actionPackages定义扫描Action类的目录 -->
<servlet>
<servlet-name>autoLoadResourceObject</servlet-name>
<servlet-class>
com.talkweb.web.servlet.ResourceAutoLoader
</servlet-class>
<load-on-startup>0</load-on-startup>
</servlet> <!-- structs2过滤器,负责与WEB容器的交互 -->
<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>*.action</url-pattern>
</filter-mapping>
<!-- structs2过滤器 -->
<!-- 配置Spring监听器 -->
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<!-- 指明spring配置文件在何处 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:applicationContext.xml</param-value>
</context-param>
<welcome-file-list>
<welcome-file>/index.jsp</welcome-file>
</welcome-file-list>
</web-app>
login.action
package com.talkweb.web.action;import com.talkweb.model.Student;
import com.talkweb.service.BaseService;
import com.talkweb.web.commom.BaseAction;public class LoginAction extends BaseAction<Student>{ private static final long serialVersionUID = 1L; private BaseService adminService;
public Student getModel() {
// TODO Auto-generated method stub
return null;
}
/**
* 登陆
* @return
* @throws Exception
*/
public String login(){
System.out.println("----------------");
String loginName = getRequestParmeterByTrim("loginName");
String password = getRequestParmeter("password");
this.getRequest().setAttribute("loginName",loginName);
if(null == loginName || "".equals(loginName)){
this.getRequest().setAttribute("msg","用户名不能为空!");
return "failure";
}else{
adminService.add();
return "success";
}
}
public BaseService getAdminService() {
return adminService;
}
public void setAdminService(BaseService adminService) {
this.adminService = adminService;
}
}
<?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> <constant name="struts.enable.DynamicMethodInvocation" value="true" /> <package name="web" extends="struts-default" namespace="">
<default-interceptor-ref name="paramsPrepareParamsStack" />
<!--登录管理 -->
<action name="login"
class="com.talkweb.web.action.LoginAction">
<result name="success">/admin/index.jsp</result>
<result name="failure">/index.jsp</result>
<result name="loginOut">/index.jsp</result>
</action> </package></struts>aplicationcontext.xml
?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"> <bean id = "StudentAdminImpl" class="com.talkweb.service.impl.StudentAdminImpl"></bean> <bean id="loginAction" class="com.talkweb.web.action.LoginAction" >
<property name="adminService" ref="StudentAdminImpl" />
</bean></beans>web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> <!-- Struts2 filter,actionPackages定义扫描Action类的目录 -->
<servlet>
<servlet-name>autoLoadResourceObject</servlet-name>
<servlet-class>
com.talkweb.web.servlet.ResourceAutoLoader
</servlet-class>
<load-on-startup>0</load-on-startup>
</servlet> <!-- structs2过滤器,负责与WEB容器的交互 -->
<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>*.action</url-pattern>
</filter-mapping>
<!-- structs2过滤器 -->
<!-- 配置Spring监听器 -->
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<!-- 指明spring配置文件在何处 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:applicationContext.xml</param-value>
</context-param>
<welcome-file-list>
<welcome-file>/index.jsp</welcome-file>
</welcome-file-list>
</web-app>
login.action
package com.talkweb.web.action;import com.talkweb.model.Student;
import com.talkweb.service.BaseService;
import com.talkweb.web.commom.BaseAction;public class LoginAction extends BaseAction<Student>{ private static final long serialVersionUID = 1L; private BaseService adminService;
public Student getModel() {
// TODO Auto-generated method stub
return null;
}
/**
* 登陆
* @return
* @throws Exception
*/
public String login(){
System.out.println("----------------");
String loginName = getRequestParmeterByTrim("loginName");
String password = getRequestParmeter("password");
this.getRequest().setAttribute("loginName",loginName);
if(null == loginName || "".equals(loginName)){
this.getRequest().setAttribute("msg","用户名不能为空!");
return "failure";
}else{
adminService.add();
return "success";
}
}
public BaseService getAdminService() {
return adminService;
}
public void setAdminService(BaseService adminService) {
this.adminService = adminService;
}
}
解决方案 »
- 访问Action出现内部服务错误
- 注销后发布程序不能访问?急!!在线等,谢谢
- 求教tomcat发布的jsp网站如何做域名解析
- js参数传递用el形式传递的问题
- 关于断点续传得到http请求头request.getHeader("Range")?
- webwork中如何使用jstl????????????????
- jasperreport做报表,生成excel时,如果数字超15位会用科学计数法表示,并且会把后面的数据变为0,请问如何解决?
- 关于随机数的问题,急!!!
- JSP上传文件时出以下错误!
- ClassNotFoundException: his.Client
- jsp页面<%%>中的this是不是指的是该页面对象本身?
- tomcat6配置全局数据源没问题,但配置局部数据源却报错!
加入 <constant name="struts.objectFactory" value="spring" />
spring才能集成
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"> <bean id = "StudentAdminImpl" class="com.talkweb.service.impl.StudentAdminImpl"></bean> <bean id="loginAction" class="com.talkweb.web.action.LoginAction" >
<property name="adminService" ref="adminDao" />
</bean>
<bean id="adminService" class="com.talkweb.web.action.adminService" >
<property name="adminDao" ref="dataBase" />
</bean>
<bean id="dataBase"> </bean></beans>在applictioncontext.xml中加入adminService的依赖对象,你adminService需要依赖adminDao...
然后adminDao依赖dateBase,都要配置
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.opache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>strtus.xml<action id="路径名" class="spring中配置的servicbean的id" >
按照你提供的代码写就是springContext.xml
<!-- ben中id改为name -->
<bean name="loginAction" class="com.talkweb.web.action.LoginAction" >
<property name="adminService" ref="StudentAdminImpl" />
</bean>struts.xml
<!-- action中的class改为spring的bean的name -->
<action name="login"
class="loginAction">
<result name="success">/admin/index.jsp</result>
<result name="failure">/index.jsp</result>
<result name="loginOut">/index.jsp</result>
</action>