spring 如何给struts2的action设置request对象的?详情见全文

在ioc环境里,在一个UserAction 要获得 request对象,可以这么实现:
让UserAction 实现ServletRequestAware接口,然后在UserAction里面写下面这个方法:
public HttpServletRequest request;//定义request属性
public void setServletRequest(HttpServletRequest request) {
this.request = request;
}
就这样可以正确使用request。
然而我的问题是什么呢? 是spring是如何给这个request赋值的? 我想知道spring内部是如何实现的?
实现这个接口后,spring 是如何给他赋值的?
请高手解释?
我的理解 是spring用了动态代理实现的,不知道对不对?
问题补充

java_bigniu 写道
HttpServletRequest request = ServletActionContext.getRequest();

我想知道,spring在哪里给他赋值的?我想知道spring内部的代码,哪块处理的?原理是什么?
你的这个方式是在非ioc的方式下获得request对象的
问题补充
其实我的意思,想明白咱们实现spring的这个接口后,spring内部是如何处理这个的? 为什么我实现这个接口后,
public void setServletRequest(HttpServletRequest request) {
this.request = request;
}
这个方法的参数HttpServletRequest request 是从哪儿传来的?
request 是怎么生成的?
问题补充
kjj 写道
晕,这有啥难的,你忘了,spring的容器是怎么初始化的么,web就是webapplicationcontext,所以,每次请求这个对象的时候,把当前线程的requet注入了

呵呵,我知道不难,我就明白,spring内部是如何实现的?在哪个类里面注入的?我看了源代码,没找到在哪儿注入啊?是动态代理实现的。

还有,这个问题不仅仅在spring里面有,在jdk里面也很普遍啊,比如让你实现某个接口,就能得到某个功能。他内部肯定是用动态代理实现的,特别是这个接口有参数的时候,这个参数就是动态代理传进来的。基于接口的就是动态代理才能实现。


问题补充
kjj 写道
晕,这有啥难的,你忘了,spring的容器是怎么初始化的么,web就是webapplicationcontext,所以,每次请求这个对象的时候,把当前线程的requet注入了


你的意思是 有个监听器:org.springframework.web.context.request.RequestContextListener
这个监听到后,会注入?
问题补充
Aaronlong31 写道
这个和spring有什么关系吗?是struts2的拦截器处理的,在struts2的默认拦截器栈中有个ServletConfigInterceptor,它会判断你是否实现了ServletRequestAware接口,如果实现了,它就帮你注入HttpServletRequest对象,这样的Aware接口还有很多,如SessionAware等。


那他的注入也是通过spring的ioc注入的,怎么没关呢?
在ioc下是实现接口可以获得request,非ioc下直接获得就行了,不用实现接口的。
问题补充
rentianchou 写道
么人所让你非得实现接口啊

嗨,标题讨论就是讨论ioc下面的情况,。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
总之感谢大家一起交流了。
问题补充
池中物 写道
这个跟spring没关系,是struts做的

明白,呵呵。拦截器的原理也是动态代理实现的,我说的没错。
问题补充
ok 明白了
问题补充
不是的,但是动态代理用的很多,aop 拦截器 filter 都是动态代理
问题补充
究其本质还是 动态代理,就是struts2的这个拦截器ServletConfigInterceptor,本质也是动态代理实现的,我说的有错吗?和动态代理能脱离关系吗?
问题补充
不是我和动态代理脱不了关系,是他们的原理实现就是这样的,我是这么理解的。
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
Spring如何给Struts生成新action对象?
**Spring3.2.12 Struts2.3.20** 看struts代码: ``` @Component @Scope(ConfigurableBeanFactory.SCOPE_SINGLETON) @ParentPackage("struts-default") @Namespace("/test") public class TestAction { private String flag; @Action(value = "testAction", results = { @Result(name = "success", location = "/index.jsp") }) public String test() { System.out.println("request struts."); try { WebApplicationContext context = WebApplicationContextUtils .getWebApplicationContext(ServletActionContext.getServletContext()); TestAction test = context.getBean("testAction", TestAction.class); System.out.println("this:" + this.flag+"\t" + this); System.out.println("spring:" + test.flag+"\t" + test); } catch (Exception e) { e.printStackTrace(); } return "success"; } @PostConstruct public void setFlag() { this.flag = "From Spring"; } ``` 运行结果: ``` request struts. this:From Spring toString:com.me.permission.action.TestAction@732efcfe spring:From Spring toString:com.me.permission.action.TestAction@2140243b request struts. this:From Spring toString:com.me.permission.action.TestAction@11e3c2c6 spring:From Spring toString:com.me.permission.action.TestAction@2140243b request struts. this:From Spring toString:com.me.permission.action.TestAction@521d590d spring:From Spring toString:com.me.permission.action.TestAction@2140243b ``` --------- 运行结果 说明,spring中持有一个TestAction的对象,而且是单例; 请求action的时候,是spring给struts生成的action,但是每一次都是新的,并不是spring所持有的那个单例,这是为什么哪? 怎么才能让spring所持有的那个单例,给struts哪?让struts每次请求都使用spring中所持有的那个单例。
一个用spring aop拦截struts action的问题
最近我需要在不改变原有的代码的前提下,记录到达struts action的HttpServletRequest和HttpServletResponse,我的第一想法就是用spring aop来做拦截。但是,这样做使得原来struts action无法获得struts上下文的内容信息,为了说明问题,我写了一个小原型,代码如下: [color=red]类SimpleAction,这个类是用来封装获得HttpServletRequest和HttpServletResponse的方法的,跟本主题关系不大,可以跳过。[/color] package action; import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.struts2.interceptor.ServletRequestAware; import org.apache.struts2.interceptor.ServletResponseAware; import org.apache.struts2.interceptor.SessionAware; import com.opensymphony.xwork2.ActionSupport; public class SimpleAction extends ActionSupport implements ServletRequestAware, ServletResponseAware ,SessionAware{ protected HttpServletRequest servletRequest; protected HttpServletResponse servletResponse; protected Map session; public Map getSession() { return session; } public void setSession(Map session) { this.session = session; } public void setServletRequest(HttpServletRequest request) { this.servletRequest = request; } public HttpServletRequest getServletRequest() { return this.servletRequest; } public void setServletResponse(HttpServletResponse response) { this.servletResponse = response; } public HttpServletResponse getServletResponse() { return this.servletResponse; } } 类LoginAction,这个类的execute就是struts处理action调用的方法,但是奇怪的是,在这个方法中,本应得到jsp传来的值得username和password为空(把spring aop相关配置注释掉之后,username和password能正常传值)。loginService.validate()用作判断username和password是否符合,不符合以抛出异常的方式来告知调用者。在加上spring aop后,由于[color=red]username和password为空[/color],所以就一直返回结果"usernameInvalid"。 package action; import org.apache.struts2.interceptor.ServletRequestAware; import org.apache.struts2.interceptor.ServletResponseAware; import org.apache.struts2.interceptor.SessionAware; import service.LoginService; import exception.*; public class LoginAction extends SimpleAction { private String username; private String password; private LoginService loginService; public LoginService getLoginService() { return loginService; } public void setLoginService(LoginService loginService) { this.loginService = loginService; } public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } @Override public void validate() { } @Override public String execute() { try{ this.getServletRequest().setAttribute("username", username); this.getServletRequest().setAttribute("password", password); System.out.println("username"+username); System.out.println("username"+getUsername()); boolean result = loginService.validate(username, password); }catch(UsernameException ue) { return "usernameInvalid"; }catch(PasswordException pe) { return "passwordInvalid"; }catch(Exception e) { e.printStackTrace(); return INPUT; } return SUCCESS; } } 下面是advice类,用来处理调用方法后的日志记录工作 package advice; import java.io.*; import java.lang.reflect.Method; import org.apache.log4j.Logger; import org.apache.log4j.PropertyConfigurator; import org.springframework.aop.AfterReturningAdvice; import org.springframework.aop.MethodBeforeAdvice; import org.springframework.aop.ThrowsAdvice; public class LogActionAdvice implements AfterReturningAdvice { public void afterReturning(Object arg0, Method arg1, Object[] arg2, Object target) { // TODO Auto-generated method stub try { PropertyConfigurator.configure("after.properties"); Logger logger = Logger.getLogger(target.getClass()); logger.debug("..."); }catch(Exception e) { e.printStackTrace(); } } } 下面是login页面,这个页面的username空间对应action的username属性,所以应该不是struts没有配alias的问题,这里是login.jsp代码 <%@ page language="java" pageEncoding="GB2312"%> <%@ taglib prefix="s" uri="/struts-tags"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//CN"> <html> <head> <title>login2</title> </head> <body> <s:form name="login" action="login" method="post" > <s:textfield name="username" label="帐号"></s:textfield> <s:password name="password" label="密码"></s:password> <s:submit></s:submit> </s:form> </body> </html> 下面是配置文件,首先是struts的配置文件struts.xml: <?xml version="1.0" encoding="GB2312" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <package name="struts2" extends="struts-default"> <action name="login" class="LoginAction"> <result name="success">/index.jsp</result> <result name="input">/login.jsp</result> <result name="usernameInvalid">/usernameInvalid.jsp</result> <result name="passwordInvalid">/passwordInvalid.jsp</result> </action> </package> </struts> 再来是spring的配置文件applicationContext.xml,红色部分是advice的配置,具体是匹配所有*Action的execute方法。 <?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:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:ehcache="http://www.springmodules.org/schema/ehcache" xmlns:context="http://www.springframework.org/schema/context" 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/tx http://www.springframework.org/schema/tx/spring-tx-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/context http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springmodules.org/schema/ehcache http://www.springmodules.org/schema/cache/springmodules-ehcache.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd" default-lazy-init="true" default-autowire="byName"> [color=red] <aop:config> <aop:advisor id="methodAroundAdviceAdvisor" advice-ref="logActionAdvice" pointcut="execution(* *..*Action.execute(..))" /> </aop:config> <bean id="logActionAdvice" class="advice.LogActionAdvice" />[/color] <bean name="loginService" class="service.LoginService" /> <bean name="LoginAction" class="action.LoginAction"> <property name="loginService"> <ref bean="loginService"/> </property> </bean> </beans> 最后是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"> <!-- 加载struts2核心 --> <filter> <filter-name>struts2</filter-name> <filter-class> org.apache.struts2.dispatcher.FilterDispatcher </filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <!-- 指明spring配置文件在何处 --> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:applicationContext.xml</param-value> </context-param> <!-- 加载spring配置文件applicationContext.xml --> <listener> <listener-class> org.springframework.web.context.ContextLoaderListener </listener-class> </listener> </web-app> 在这个原型中出现的问题是,在LoginAction中,username和password为空,但是,[color=red]如果把它们set到 HttpServletRequest中,在页面usernameInvalid.jsp中却能够得到username和password的值。[/color]事先我查过一些资料,说用spring aop自动生成的代理无法获得struts上下文传递的变量值,但是我想不通为何把它们set到HttpServletRequest后却能够在前端页面显示出正确的值。 谢谢您的阅读和帮助!
关于spring 管理 struts action的问题
在Struts中存在两个路径 "/demo" 和 "/demo1" . 这两个路径请求的都是同一个action(com.struts.action.DemoAction). struts-config.xml <action path="/demo" parameter="demo"/> <action path="/demo1" parameter="demo1"/> 如果spring是通过xml配置的方式管理的话 , 可以通过以下配置来实现 将同一个action在spring容器中注册两个值 <bean name = "/demo" class = "com.struts.action.DemoAction"/> <bean name = "/demo1" class = "com.struts.action.DemoAction"/> 请教: 如果我是通过注解的方式去加载action的话,怎么样实现以上功能 [color=orange]@Controller("/demo")[/color] public class DemoAction extends MappingDispatchAction { public ActionForward demo(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { System.out.println("demo"); return mapping.findForward("success"); } public ActionForward demo1(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { System.out.println("demo1"); return mapping.findForward("success"); } } 以上配置只有在请求路径为"/demo"的时候才能访问到这个action , 如果路径为"/demo1"时这个注解要怎么写 .
struts2+spring 中action 的 scope如何设置?
如题,如何设置?设置成request 与 protype有什么区别,我设置成request,spring却报错 org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'bdnAction': Scope 'request' is not active for the current thread; consider defining a scoped proxy for this bean if you intend to refer to it from a singleton; nested exception is java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet/DispatcherPortlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request. 查了好多,不知所云. 不知道怎么解决,请'验证失败 :wink: '迷津!!
struts 2 action问题
struts 2 action的值是不是放在session中?是的话,怎样在每次重新发起request时把上次action里的值清掉? [b]问题补充:[/b] 不过,我碰到一个问题: 客户端发出一个请求到服务器,服务器执行Action1(Action1里面包含一个变量field1,初始值为null)。执行完Action1后,field1的值变为“123“。然后返回客户端。接着,客户端再次发出一个请求到服务器,服务器再次执行Action1,这是发现field1的初始值为“123“.为什么?怎么解决? [b]问题补充:[/b] To netfork: [quote]楼主不会把action作为单例了吧。。。 如果是基于struts2 + spring,千万不要把action作为单例设定,这样会多线程共享成员变量。[/quote] 我是基于struts2 + spring,能否给多点指导“楼主不会把action作为单例了吧“? ********************* To lovewhzlq: [quote]那是客户端再次发出一个请求里包含了field1的值,struts自动绑定到action里[/quote] 第二次请求应该没有包含field1的值,我的代码是这样的 [code="java"] <A href="<s:url action="courseRetrieve"> <s:param name="courseType">fixed</s:param> <s:param name="actionType">createCourse</s:param></s:url>"> create course </A>[/code] 这个链接没有把field1的值作为参数传过去。 [b]问题补充:[/b] Action的代码是: [quote]public class CourseRetrieveAction extends ActionSupport { .....[/quote] [b]问题补充:[/b] To lovewhzlq: [quote]对了,你的spring配置struts的bean,不能设置为配置单例啊 要设置scope ="prototype"[/quote] 不好意思,小弟刚学struts不是很久,能否弱弱的问下在哪里设置scope ="prototype"?是不是struts.xml里的<action>的属性?谢谢!
Spring注入的Struts Action与运行时取得的不是一个,如何改对?
使用Spring/Struts/OpenJPA时遇到初始Spring注入的Struts Action与运行时取得的不是一个: 1. applicationContext.xml [code="xml"]... <!-- Struts Actions --> <bean name="/author" class="com.example.myproject.view.AuthorAction"> <property name="authorService"> <ref bean="authorService"/> </property> </bean> <!-- Business Services --> <bean id="authorService" class="com.example.myproject.service.AuthorServiceImpl"> <property name="authorDao" ref="authorDao"/> </bean> <!-- Data Access Objects --> <bean id="authorDao" class="com.example.myproject.persistence.dao.AuthorDAOImpl"> <property name="entityManagerFactory" ref="entityManagerFactory"/> </bean> ...[/code] 2. AuthorAction.java [code="java"]public class AuthorAction extends DispatchAction { private AuthorService authorService; public AuthorService getAuthorService() { return authorService; } public void setAuthorService(AuthorService authorService) { this.authorService = authorService; } public ActionForward list(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) { List<Author> result = authorService.findByName("hello"); request.setAttribute(Constant.LIST, result); return mapping.findForward(Constant.FWD_LIST); } ... } [/code] 调试AuthorAction.Java,将断点设在第9行和第15行,得到的两个不同的AuthorAction实例(请见附图)。请问这是什么原因,如何才能改对?
关于struts2和spring整合的问题
以前培训的时候讲到过这个,整合正常的做法是导入struts2-spring-plugin.jar包,然后在struts.xml里面配置action标签的class属性时直接写创建action类的bean id的名字,而不是直接写类的路径,当然new action类是通过spring来创建bean的(不管是注解方式还是xml方式),但是实验结果是就算不导入struts2-spring-plugin.jar包,struts.xml里面配置action标签的class属性时直接写类的路径,并且也不用spring来new action类也是可以将struts2和spring整合起来的,下面我贴下一个实验代码: (没有导入struts2-spring-plugin.jar) applicationContext.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:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd"> <!-- 设置需要进行Spring注解扫描的类包 --> <context:component-scan base-package="com.niit" /> </beans> struts2.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.devMode" value="true" /> <constant name="struts.enable.DynamicMethodInvocation" value="true" /> <package name="root" namespace="/" extends="struts-default"> <action name="user" class="com.niit.test.UserAction" > <result name="res">/res.jsp</result> </action> </package> </struts> 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"> <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> <!-- 定义Spring配置文件位置 --> <context-param> <param-name>contextConfigLocation</param-name> <param-value> classpath:applicationContext.xml </param-value> </context-param> <!-- 对Spring容器进行实例化 --> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> </web-app> index.jsp: <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <title>My JSP 'index.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> --> </head> <body> <a href="user!sss.action">111</a> <br> </body> </html> res.jsp: <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <title>My JSP 'res.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> --> </head> <body> res <br> </body> </html> UserAction.java: package com.niit.test; import javax.annotation.Resource; public class UserAction { @Resource private UserServiceInterface userService; public String sss(){ userService.asd(); return "res"; } public UserServiceInterface getUserService() { return userService; } public void setUserService(UserServiceInterface userService) { this.userService = userService; } } UserService.java: package com.niit.test; import org.springframework.stereotype.Service; @Service public class UserService implements UserServiceInterface{ public void asd(){ System.out.println("asd"); } } UserServiceInterface.java: package com.niit.test; public interface UserServiceInterface { public void asd(); } 我的疑问就是应该是struts2自己new了一个UserAction实例,但是这个实例并没有交给spring管理啊,这个UserAction实例里面的userService属性应该是不会被spring注入实例的,但是为什么UserAction里面还是拿到了userService并且没有报nullpoint错误,实验的结果说明了struts2创建的UserAction实例确实交给spring了,这是为什么呢
Struts1.2的 Action中获取servletConfig空指针?
大家好, 我用Struts+Spring +Hibernate 整和框架, 将 Struts 的 action 交由 Spring 管理了, 但是我在 Action中使用 this.getServlet().getServletConfig()获取servletConfig 却出现空指针异常, 怎么都想不通?  ( 我使用jspsmartupload上传控件, 在Action 中初始化SmartUpload 对象 SmartUpload su = new SmartUpload(); su.initialize(this.getServlet().getServletConfig(), request, response); ) [b]问题补充:[/b] 3位兄弟的回答都不是我要问的, 使用 jspsmartupload 上传,首先需要初始化smartupload对象,在jsp中使用,使用 :pageContext参数来初始化 [code="java"] SmartUpload su = new SmartUpload(); su.initialize(pageContext); [/code] 但是,在action 中,只能使用它的另一个初始化方法:(action中无法获取pageContext) [code="java"] su.initialize(this.getServlet().getServletConfig(), request, response); [/code] 现在,action交由 Spring 托管了,结果却无法使用 this.getServlet()来获取servlet了........ 有什么方法可以解决啊???????
Struts2 与spring集成问题
<p>  今天集成的时候出错了     从页面到action都能进   但是一到调用就后台方法的时候就出错  集成spring用的jar文件也加了   下面把几个相关文件都拷出来了</p> <p> web.xml</p> <pre name="code" class="xml">&lt;filter&gt; &lt;filter-name&gt;struts2&lt;/filter-name&gt; &lt;filter-class&gt;org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter&lt;/filter-class&gt; &lt;/filter&gt; &lt;filter-mapping&gt; &lt;filter-name&gt;struts2&lt;/filter-name&gt; &lt;url-pattern&gt;/*&lt;/url-pattern&gt; &lt;/filter-mapping&gt; &lt;listener&gt; &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt; &lt;/listener&gt; &lt;context-param&gt; &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt; &lt;param-value&gt;classpath:/applicationContext.xml&lt;/param-value&gt; &lt;/context-param&gt;</pre> <p> struts.xml</p> <pre name="code" class="xml"> &lt;package name="default" namespace="/" extends="struts-default"&gt; &lt;action name="*marketInfo" class="com.btm.crm.crmAction.marketAction" method="{1}marketInfo"&gt; &lt;result name="marketAction" type="chain"&gt;marketAction&lt;/result&gt; &lt;result name="marketlist"&gt;/html/~sale/list.jsp&lt;/result&gt; &lt;/action&gt; &lt;/package&gt;</pre> <p> applicationContext.xml</p> <pre name="code" class="xml"> &lt;!-- 配置Action --&gt; &lt;bean id="marketAction" class="com.btm.crm.crmAction.marketAction"&gt; &lt;property name="marketBiz" ref="marketManagerBiz" /&gt; &lt;/bean&gt;</pre> <p> </p> <p>Action </p> <pre name="code" class="java">类已经继承了ActionSupport public String getAllmarketInfo(){ System.out.println(11); PageResult pageresult= marketBiz.getAllSalInfo(new PageResult()); List&lt;SalChance&gt; marketList = pageresult.getList(); for (SalChance chance : marketList) { System.out.println(chance.getChcCustName()); } return null; }</pre> <p> 让人郁闷的问题 还有html500错误</p> <pre name="code" class="html">type Exception report message description The server encountered an internal error () that prevented it from fulfilling this request. exception java.lang.NullPointerException com.btm.crm.crmAction.marketAction.getAllmarketInfo(marketAction.java:28) sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) java.lang.reflect.Method.invoke(Method.java:597) com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:440) com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:279) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242) com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:163) com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:249) org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68) com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:122) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:195) com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:195) com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:148) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:93) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:235) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:89) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:128) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) org.apache.struts2.interceptor.ProfilingActivationInterceptor.intercept(ProfilingActivationInterceptor.java:104) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:267) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:126) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:138) com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:148) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:128) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:176) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:52) org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:468) org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77) org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:76) com.btm.crm.Filter.reFilter.doFilter(reFilter.java:25) note The full stack trace of the root cause is available in the Apache Tomcat/6.0.10 logs. </pre> <p> </p> <p>  希望帮忙gs解决下</p>
spring与struts整合问题
[code="java"]<plug-in className="org.springframework.web.struts.ContextLoaderPlugIn"> <set-property property="contextConfigLocation" value="classpath:applicationContext.xml"/> </plug-in> [/code] 以上代码没有配置在struts-config.xml中,我看书上说,如果使用DelegatingActionProxy整合的话,必须把上面的代码写到配置文件里, 我的配置文件中没有,为什么程序可以执行起来,在IE上输入URL可以访问,在页面上提交数据也不会出错,知道的请告诉一下,谢谢了! applicationContext.xml配置 [code="java"]<?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:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd "> <bean name="/login" class="com.maesinfo.action.UserLevelAction"> <property name="userservice"> <ref bean="userservice" /> </property> </bean> <bean id="userservice" class="com.maesinfo.service.UserServiceImpl"> <property name="userleveldao"> <ref bean="userleveldao" /> </property> <property name="userdao"> <ref bean="userdao" /> </property> </bean> <bean id="userleveldao" class="com.maesinfo.dao.UserlevelDAO" /> <bean id="userdao" class="com.maesinfo.dao.UserDAO" /> <bean id="checkUser" class="com.maesinfo.util.CheckUserLevel" /> <aop:config> <aop:pointcut id="allcheckmothod" expression="execution(* com.maesinfo.service.UserService.check*(..))"/> <aop:aspect id="checkuser" ref="checkUser"> <aop:before method="checkLevel" pointcut-ref="allcheckmothod"/> </aop:aspect> </aop:config> </beans>[/code] struts-config.xml配置 [code="java"]<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd"> <struts-config> <action-mappings> <action path="/login" parameter="login" type="org.springframework.web.struts.DelegatingActionProxy" scope="request"> <forward name="success" path="/index.jsp"/> </action> </action-mappings> <message-resources parameter="com.yourcompany.struts.ApplicationResources" /> <!-- spring与struts整合:把struts的Action托管给spring <plug-in className="org.springframework.web.struts.ContextLoaderPlugIn"> <set-property property="contextConfigLocation" value="classpath:applicationContext.xml"/> </plug-in> --> </struts-config> [/code] [b]问题补充:[/b] <pre name="code" class="java">&lt;plug-in className="org.springframework.web.struts.ContextLoaderPlugIn"&gt; &lt;set-property property="contextConfigLocation" value="classpath:applicationContext.xml"/&gt; &lt;/plug-in&gt; </pre> 以上代码没有配置在struts-config.xml中,我看书上说,如果使用DelegatingActionProxy整合的话,必须把上面的代码写到配置文件里, 我的配置文件中没有,为什么程序可以执行起来,在IE上输入URL可以访问,在页面上提交数据也不会出错,知道的请告诉一下,谢谢了! applicationContext.xml配置 <pre name="code" class="java">&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 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.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd "&gt; &lt;bean name="/login" class="com.maesinfo.action.UserLevelAction"&gt; &lt;property name="userservice"&gt; &lt;ref bean="userservice" /&gt; &lt;/property&gt; &lt;/bean&gt; &lt;bean id="userservice" class="com.maesinfo.service.UserServiceImpl"&gt; &lt;property name="userleveldao"&gt; &lt;ref bean="userleveldao" /&gt; &lt;/property&gt; &lt;property name="userdao"&gt; &lt;ref bean="userdao" /&gt; &lt;/property&gt; &lt;/bean&gt; &lt;bean id="userleveldao" class="com.maesinfo.dao.UserlevelDAO" /&gt; &lt;bean id="userdao" class="com.maesinfo.dao.UserDAO" /&gt; &lt;bean id="checkUser" class="com.maesinfo.util.CheckUserLevel" /&gt; &lt;aop:config&gt; &lt;aop:pointcut id="allcheckmothod" expression="execution(* com.maesinfo.service.UserService.check*(..))"/&gt; &lt;aop:aspect id="checkuser" ref="checkUser"&gt; &lt;aop:before method="checkLevel" pointcut-ref="allcheckmothod"/&gt; &lt;/aop:aspect&gt; &lt;/aop:config&gt; &lt;/beans&gt;</pre> struts-config.xml配置 <pre name="code" class="java">&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd"&gt; &lt;struts-config&gt; &lt;action-mappings&gt; &lt;action path="/login" parameter="login" type="org.springframework.web.struts.DelegatingActionProxy" scope="request"&gt; &lt;forward name="success" path="/index.jsp"/&gt; &lt;/action&gt; &lt;/action-mappings&gt; &lt;message-resources parameter="com.yourcompany.struts.ApplicationResources" /&gt; &lt;!-- spring与struts整合:把struts的Action托管给spring &lt;plug-in className="org.springframework.web.struts.ContextLoaderPlugIn"&gt; &lt;set-property property="contextConfigLocation" value="classpath:applicationContext.xml"/&gt; &lt;/plug-in&gt; --&gt; &lt;/struts-config&gt; </pre> 页面只是一个登陆页面,点击确定之后,调用login.do,然后判断一下,用户名和密码! [b]问题补充:[/b] 页面只是一个登陆页面,点击确定之后,调用login.do,然后判断一下,用户名和密码! [b]问题补充:[/b] 配置都在上面了! 我把下面这段配置拿掉了,程序也可以运行,但是不报错 有些书上介绍说,用DelegatingActionProxy整合,下面的配置必须加上! 我想知道为什么我的程序还可以运行?而且不报错误。 [code="java"]<plug-in className="org.springframework.web.struts.ContextLoaderPlugIn"> <set-property property="contextConfigLocation" value="classpath:applicationContext.xml"/> </plug-in> [/code] [b]问题补充:[/b] [code="java"]<context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:applicationContext.xml</param-value> </context-param> <servlet> <servlet-name>SpringContextServlet</servlet-name> <servlet-class> org.springframework.web.context.ContextLoaderServlet </servlet-class> <load-on-startup>1</load-on-startup> </servlet> [/code] 我在web.xml加了上面的代码,是不是struts-config.xml中就不用加<plug-in>的代码了? 在web.xml加了这段代码之后,可以访问! 这两段代码有什么区别? 谢谢!
Struts2+Spring+Hibernate问题
[size=large]程序可以成功部署,也可以成功的从数据库中读取数据!但是就是不能更新数据。。。一更新就会报下面这样的错误!! [/size]HTTP Status 500 - -------------------------------------------------------------------------------- type Exception report message description The server encountered an internal error () that prevented it from fulfilling this request. exception java.lang.reflect.InvocationTargetException sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) java.lang.reflect.Method.invoke(Unknown Source) com.opensymphony.xwork2.DefaultActionInvocation.invokeAction (DefaultActionInvocation.java:441) com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:280) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:243) com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:165) com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:252) org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68) com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:122) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:195) com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:195) com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:179) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:94) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:235) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:89) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:130) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:267) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:126) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:138) com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:165) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:179) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:176) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:52) org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:488) org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:395) root cause java.lang.NoSuchMethodError: org.hibernate.event.PreUpdateEvent.getSource()Lorg/hibernate/engine/SessionImplementor; org.hibernate.validator.event.ValidateEventListener.onPreUpdate(ValidateEventListener.java:177) org.hibernate.action.EntityUpdateAction.preUpdate(EntityUpdateAction.java:237) org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:88) org.hibernate.engine.ActionQueue.execute(ActionQueue.java:279) org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:263) org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:168) org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321) org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50) org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1028) org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:366) org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:137) org.springframework.orm.hibernate3.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:655) org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:732) org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:701) org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:321) org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:116) org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171) org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204) $Proxy34.update(Unknown Source) cn.com.blog.action.BlogAction.update(BlogAction.java:34) sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) java.lang.reflect.Method.invoke(Unknown Source) com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:441) com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:280) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:243) com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:165) com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:252) org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68) com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:122) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:195) com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:195) com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:179) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:94) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:235) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:89) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:130) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:267) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:126) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:138) com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:165) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:179) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:176) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237) org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:52) org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:488) org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:395) note The full stack trace of the root cause is available in the Apache Tomcat/6.0.20 logs. [b]而且在后台出现如下警告:[/b] 2397969 [http-8080-1] WARN org.hibernate.cache.ReadWriteCache - An item was expired by the cache while it was locked (increase your cache timeout): cn.com.blog.model.Blog#1 [b]问题补充:[/b] 我用到的版本是: Struts2.1.8 + Hibernate3.3+Spring2.5 其中Spring和Hibernate是用MyEclipse自动添加的,Struts 是我自己加进去的 [b]问题补充:[/b] 我引入了Struts-core.jar文件 好像在Spring2.5有Struts.jar文件 会不会是这个问题呢? ———————————————————————————————————
struts2和spring结合问题,很着急啊。。。
我用struts2和spring结合的时候出错了,已经3天了,希望大家帮忙哈,小弟真的很急啊。。。 我action里面这样配置的,采取让spring管理action @Component("woyun") @Scope("prototype") public class OrgAction extends ActionSupport implements RequestAware{ @Override public String execute() throws Exception { System.out.println(parentId); //System.out.println(orgManager.findOrgs(parentId)); //request.put("orgs", orgManager.findOrgs(parentId)); return SUCCESS; struts 配置文件是这样配的: <constant name="struts.devMode" value="true" /> <package name="front" extends="struts-default" namespace="/"> <action name="org" class="woyun"> <result>/org/index.jsp</result> <result name="add_input">/org/add_input.jsp</result> <result name="add_success">/org/add_success.jsp</result> <result name="del_success">/org/del_success.jsp</result> 但是总是出错啊 : Caused by: Action class [woyun] not found - action - file:/D:/apache-tomcat-6.0.16/webapps/oa_01/WEB-INF/classes/struts.xml:11:42 大哥们,难道我这样配置出错了吗》?这是老师讲的让spring来管理action啊,为什么不能啊 ,还有啊 即使我action里面什么都不写, 配置文件写全名字,这样也不行啊????哎 真的好难受啊,谁知道赶紧和我说说哈!!万分感谢啊
Ext.Ajax.request怎么传递对象到后台Action
var cell=grid.getSelectionModel().each(function(rec){ // var jsonBean={dept:{id:rec.get('dept.id'),CDept:rec.get('dept.cDept'),CDeptname:rec.get('dept.cDeptname')}}; //var newJson=Ext.encode(Ext.decode(jsonBean)); Ext.Ajax.request({ url: 'addTJdept.action', method: 'POST', scope: this, params:{ id:rec.get('dept.id') }, success: function(response, opts){ 。。。。。。。。。。。。。 我用的是Struts2+Spring+Hibernate+Extjs 是用Extjs的EditorGridPanel进行修改,不能弹出修改窗体,就直接在表格里修改,然后点击保存提交 上面我注释掉的代码是测试用的 可以获得我选择行的任何值 不过下面的params传参 只能传个字段,不能传一个对象么? 如果用form表单的话,Struts2会自动帮我填充到对象中, Ext.ajax.request不行么? 我的action返回的是JSON对象的,这里主要就是传个dept这个对象该怎么传到后台Action中
struts2 注解开发问题!!!!!!!!
使用注解的,之前好像还没问题来着...现在不知道问题出在哪里了 action ```package com.sg.action; import javax.annotation.Resource; import org.apache.struts2.convention.annotation.Action; import org.apache.struts2.convention.annotation.Namespace; import org.apache.struts2.convention.annotation.Result; import org.springframework.stereotype.Controller; import com.opensymphony.xwork2.ActionSupport; import com.sg.service.ArtileService; @Controller @Namespace("") @Action(value="test" ,results={ @Result (name="success" ,location="./jsp/top.jsp"), @Result (name="fail" ,location="./jsp/top.jsp") }) public class aritcleAction extends ActionSupport{ @Resource ArtileService as; public String execute(){ System.out.println("aaaa"); return"fail"; } } ``` jsp ```<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <%@taglib prefix="s" uri="/struts-tags"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> </head> <body> <s:form action="test"> <s:submit></s:submit> </s:form> </body> </html> ``` 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> <!-- 请求参数的编码方式--> <constant name="struts.i18n.encoding" value="UTF-8"/> <!-- 指定被struts2处理的请求后缀类型。多个用逗号隔开--> <constant name="struts.action.extension" value="action,do,html"/> <!-- 当struts.xml改动后,是否重新加载。默认值为false(生产环境下使用),开发阶段最好打开 --> <constant name="struts.configuration.xml.reload" value="true"/> <!-- 是否使用struts的开发模式。开发模式会有更多的调试信息。默认值为false(生产环境下使用),开发阶段最好打开 --> <constant name="struts.devMode" value="true"/> <!-- 设置浏览器是否缓存静态内容。默认值为true(生产环境下使用),开发阶段最好关闭 --> <constant name="struts.serve.static.browserCache" value="false" /> <!-- 指定由spring负责action对象的创建 <constant name="struts.objectFactory" value="spring" /> --> <!-- 是否开启动态方法调用--> <constant name="struts.enable.DynamicMethodInvocation" value="false"/> </struts> ``` 1.页面提交的时候访问路径http://localhost:8080/sg/jsp/test,后面的.action怎么不见了? 2.http://localhost:8080/sg/jsp/test.action访问就下面的报错了 There is no Action mapped for namespace /jsp and action name test. - [unknown location] namespace("")默认命名空间好像就不会因为命名空间的问题而找不到了吧,namespace("/jsp")试了,不行 所以是这个注解基本没有生效的意思吗? 问题出在哪里呢........?? 补充一个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"> <!-- 加载spring配置文件 --> <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> <!-- struts2 的配置 --> <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> <display-name></display-name> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> </web-app> ```
struts2+spring2.5+hibernate整合的问题
<p>ssh整合的时候不报错,但插入的时候数据库也没有数据,控制台把insert语句已经打出来了,这是什么情况,请大侠们帮忙看看 <br><br><br>applicationContext.xml 配置如下:</p> <p> </p> <p>&lt;?xml version="1.0" encoding="UTF-8"?&gt;<br>&lt;beans xmlns="<a href="http://www.springframework.org/schema/beans">http://www.springframework.org/schema/beans</a>"<br>xmlns:context="<a href="http://www.springframework.org/schema/context">http://www.springframework.org/schema/context</a>"<br>xmlns:tx="<a href="http://www.springframework.org/schema/tx">http://www.springframework.org/schema/tx</a>"<br>xmlns:aop="<a href="http://www.springframework.org/schema/aop">http://www.springframework.org/schema/aop</a>"<br> xmlns:xsi="<a href="http://www.w3.org/2001/XMLSchema-instance">http://www.w3.org/2001/XMLSchema-instance</a>"<br> xsi:schemaLocation="<a href="http://www.springframework.org/schema/beans">http://www.springframework.org/schema/beans</a><br><a href="http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">http://www.springframework.org/schema/beans/spring-beans-2.5.xsd</a><br><a href="http://www.springframework.org/schema/tx">http://www.springframework.org/schema/tx</a><br><a href="http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">http://www.springframework.org/schema/tx/spring-tx-2.5.xsd</a><br><a href="http://www.springframework.org/schema/aop">http://www.springframework.org/schema/aop</a><br><a href="http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">http://www.springframework.org/schema/aop/spring-aop-2.5.xsd</a><br><a href="http://www.springframework.org/schema/context">http://www.springframework.org/schema/context</a><br><a href="http://www.springframework.org/schema/context/spring-context-2.5.xsd">http://www.springframework.org/schema/context/spring-context-2.5.xsd</a><br>" default-autowire="byName" default-lazy-init="true"&gt;</p> <p> &lt;bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"&gt;<br>  &lt;property name="locations"&gt;<br>   &lt;list&gt;<br>    &lt;value&gt;classpath*:jdbc.properties&lt;/value&gt;<br>   &lt;/list&gt;<br>  &lt;/property&gt;<br> &lt;/bean&gt;<br> <br> &lt;bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"&gt;<br>  &lt;property name="driverClassName" value="${jdbc.driver}"/&gt;<br>  &lt;property name="url" value="${jdbc.url}"/&gt;<br>  &lt;property name="username" value="${jdbc.username}"/&gt;<br>  &lt;property name="password" value="${jdbc.password}"&gt;&lt;/property&gt;<br>  <br>  &lt;property name="initialSize" value="5" /&gt;<br>  &lt;property name="maxActive" value="100" /&gt;<br>  &lt;property name="maxIdle" value="30" /&gt;<br>  &lt;property name="maxWait" value="500" /&gt;<br>  &lt;property name="poolPreparedStatements" value="false" /&gt;<br>  &lt;property name="defaultAutoCommit" value="false" /&gt;<br> &lt;/bean&gt;<br> <br> &lt;bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"&gt;<br>     &lt;property name="dataSource" ref="dataSource"/&gt;<br>     &lt;property name="mappingResources"&gt;<br>       &lt;list&gt;<br>         &lt;value&gt;com/demo/mapping/demo.hbm.xml&lt;/value&gt;<br>       &lt;/list&gt;<br>     &lt;/property&gt;<br>  &lt;property name="hibernateProperties"&gt;<br>   &lt;props&gt;<br>    &lt;prop key="hibernate.dialect"&gt;org.hibernate.dialect.OracleDialect&lt;/prop&gt;<br>       &lt;prop key="hibernate.show_sql"&gt;true&lt;/prop&gt;<br>   &lt;/props&gt;<br>  &lt;/property&gt;<br>  <br> &lt;/bean&gt;<br> <br> &lt;bean id="dDao" class="com.demo.dao.Impl.demoDaoImpl"&gt;<br>  &lt;property name="sessionFactory" ref="sessionFactory"&gt;&lt;/property&gt;<br> &lt;/bean&gt;<br> <br> &lt;bean id="dService" class="com.demo.service.Impl.demoServiceImpl"&gt;<br>  &lt;property name="dDao" ref="dDao"&gt;&lt;/property&gt;<br> &lt;/bean&gt;<br> &lt;bean id="txManage" class="org.springframework.orm.hibernate3.HibernateTransactionManager"&gt;  <br>     &lt;property name="sessionFactory" ref="sessionFactory"/&gt;  <br> &lt;/bean&gt;  </p> <p>&lt;/beans&gt;</p> <p> </p> <p>struts.xml 如下:</p> <p> </p> <p>&lt;?xml version="1.0" encoding="UTF-8" ?&gt;<br>&lt;!DOCTYPE struts PUBLIC<br>    "-//Apache Software Foundation//DTD Struts Configuration 2.1.7//EN"<br>    "<a href="http://struts.apache.org/dtds/struts-2.1.7.dtd">http://struts.apache.org/dtds/struts-2.1.7.dtd</a>"&gt;<br>&lt;struts&gt;<br> &lt;package name="demo" namespace="/demo" extends="struts-default"&gt;<br>  &lt;action name="demo" class="com.demo.action.RegisterAction"&gt;<br>   &lt;result name="index"&gt;/demo/demo-index.jsp&lt;/result&gt;<br>   &lt;result name="add"&gt;/demo/demo-add.jsp&lt;/result&gt;<br>   &lt;result name="operate"&gt;/demo/demo-add.jsp&lt;/result&gt;<br>   &lt;result name="save" type="redirectAction"&gt;demo!index.action&lt;/result&gt;<br>   &lt;result name="update" type="redirectAction"&gt;demo!index.action&lt;/result&gt;<br>   &lt;result name="delete" type="redirectAction"&gt;demo!index.action&lt;/result&gt;<br>  &lt;/action&gt;<br> &lt;/package&gt;<br>&lt;/struts&gt;</p> <p> </p> <p>jdbc.properties  如下:</p> <p> </p> <p>jdbc.driver=oracle.jdbc.driver.OracleDriver<br>jdbc.url=jdbc:oracle:thin:@192.168.6.90:1521:orcl<br>jdbc.username=example<br>jdbc.password=123456<br>hibernate.dialect=org.hibernate.dialect.Oracle10gDialect</p> <p> </p> <p>web.xml   如下:</p> <p>&lt;?xml version="1.0" encoding="UTF-8"?&gt;<br>&lt;web-app version="2.5" xmlns="<a href="http://java.sun.com/xml/ns/javaee">http://java.sun.com/xml/ns/javaee</a>"<br> xmlns:xsi="<a href="http://www.w3.org/2001/XMLSchema-instance">http://www.w3.org/2001/XMLSchema-instance</a>"<br> xsi:schemaLocation="<a href="http://java.sun.com/xml/ns/javaee">http://java.sun.com/xml/ns/javaee</a> <br> <a href="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd</a>"&gt;<br> <br>    &lt;context-param&gt;<br>   &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;<br>   &lt;param-value&gt;classpath:applicationContext.xml&lt;/param-value&gt;<br>    &lt;/context-param&gt;<br>  &lt;listener&gt;<br>      &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt;<br>     &lt;/listener&gt;<br>  &lt;filter&gt;<br>   &lt;filter-name&gt;struts2Filter&lt;/filter-name&gt;<br>   &lt;filter-class&gt;org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter&lt;/filter-class&gt;<br>  &lt;/filter&gt;<br>  &lt;filter-mapping&gt;<br>   &lt;filter-name&gt;struts2Filter&lt;/filter-name&gt;<br>   &lt;url-pattern&gt;/*&lt;/url-pattern&gt;<br>  &lt;/filter-mapping&gt;<br>&lt;/web-app&gt;<br> </p> <p>dao  接口如下:</p> <p>package com.demo.dao;</p> <p>import java.io.Serializable;<br>import java.util.List;</p> <p>import com.demo.model.Demo;</p> <p>public interface demoDao {<br> <br> public void save(Demo demo);</p> <p> public List&lt;Demo&gt; getDemos(final String strHql,final Object...params);<br> <br> public List&lt;Demo&gt; getDemos();<br> <br> public void delete(Demo demo);<br> <br> public abstract &lt;T&gt; T findByPrimaryKey(Class&lt;T&gt; class1, Serializable serializable);<br> <br> public void update(Demo demo);<br>}</p> <p>dao的实现:</p> <p>package com.demo.dao.Impl;</p> <p>import java.io.Serializable;<br>import java.sql.SQLException;<br>import java.util.ArrayList;<br>import java.util.List;</p> <p>import org.hibernate.HibernateException;<br>import org.hibernate.Query;<br>import org.hibernate.Session;<br>import org.springframework.orm.hibernate3.HibernateCallback;<br>import org.springframework.orm.hibernate3.HibernateTemplate;<br>import org.springframework.orm.hibernate3.support.HibernateDaoSupport;<br>import org.springframework.transaction.annotation.Transactional;</p> <p>import com.demo.dao.demoDao;<br>import com.demo.model.Demo;</p> <p>public class demoDaoImpl  extends HibernateDaoSupport implements demoDao{</p> <p> @Transactional<br> public void save(Demo demo) {<br>  this.getHibernateTemplate().save(demo);<br> }</p> <p> @SuppressWarnings("unchecked")<br> public List&lt;Demo&gt; getDemos(final String strHql,final Object...params) {<br>  List&lt;Demo&gt; demos=new ArrayList&lt;Demo&gt;();<br>  demos=this.getHibernateTemplate().executeFind(new HibernateCallback() {<br>     public Object doInHibernate(Session session) throws HibernateException,SQLException {<br>      Query query=session.createQuery(strHql);<br>      for(int i=0;params!=null&amp;&amp;i&lt;params.length;i++){<br>       query.setString(i,params[i].toString());<br>      }<br>      return query.list();<br>   }<br>  });<br>  return demos;<br> }</p> <p> public void delete(Demo demo) {<br>  this.getHibernateTemplate().delete(demo);<br> }</p> <p>  @SuppressWarnings("unchecked")<br>  public &lt;T&gt; T findByPrimaryKey(Class&lt;T&gt; clazz, Serializable key) {<br>         T obj = (T) getSession().get(clazz, key);<br>         return obj;<br>     }</p> <p> public void update(Demo demo) {<br>  this.getHibernateTemplate().update(demo);<br> }</p> <p>  @SuppressWarnings("unchecked")<br> public List&lt;Demo&gt; getDemos() {<br>  return this.getHibernateTemplate().find("from Demo where 1=1");<br> }</p> <p> <br>}</p> <p>service接口:</p> <p>package com.demo.service;</p> <p>import java.io.Serializable;<br>import java.util.List;</p> <p>import com.demo.model.Demo;</p> <p>public interface demoService {<br> <br> public void save(Demo demo);<br> <br> public List&lt;Demo&gt; getDemos(final String strHql,final Object...params);<br> <br> public List&lt;Demo&gt; getDemos();<br> <br> public void delete(Demo demo);<br> <br> public &lt;T&gt; T findByPrimaryKey(Class&lt;T&gt; class1, Serializable serializable);<br> <br> public String createHql(Demo demo);<br> <br> public void update(Demo demo);<br>}</p> <p>service 的实现:</p> <p>package com.demo.service.Impl;</p> <p>import java.io.Serializable;<br>import java.util.List;</p> <p>import org.springframework.transaction.annotation.Transactional;</p> <p>import com.demo.dao.demoDao;<br>import com.demo.model.Demo;<br>import com.demo.service.demoService;</p> <p>public class demoServiceImpl implements demoService{</p> <p> private demoDao dDao;</p> <p> public demoDao getdDao() {<br>  return dDao;<br> }</p> <p> public void setdDao(demoDao dDao) {<br>  this.dDao = dDao;<br> }</p> <p> public void save(Demo demo) {<br>  dDao.save(demo);<br> }</p> <p> public List&lt;Demo&gt; getDemos(final String strHql,final Object...params) {<br>  return dDao.getDemos(strHql, params);<br> }</p> <p> public void delete(Demo demo) {<br>  dDao.delete(demo);<br> }</p> <p> @Override<br> public String createHql(Demo demo) {<br>  StringBuffer buf=new StringBuffer();<br>  buf.append("from Demo d where 1=1");<br>  if(demo!=null){<br>   buf.append("and d.name like '%"+demo.getName()+"%'");<br>  }<br>  return buf.toString();<br> }</p> <p> @Override<br> public &lt;T&gt; T findByPrimaryKey(Class&lt;T&gt; class1, Serializable serializable) {<br>  return dDao.findByPrimaryKey(class1, serializable);<br> }</p> <p> @Override<br> public void update(Demo demo) {<br>  dDao.update(demo);<br> }</p> <p> @Override<br> public List&lt;Demo&gt; getDemos() {<br>  return dDao.getDemos();<br> }<br>}<br><br>action 如下:</p> <p> </p> <p>package com.demo.action;</p> <p><br>import java.util.List;</p> <p>import com.demo.model.Demo;<br>import com.demo.service.demoService;</p> <p>public class RegisterAction {</p> <p> private Demo demo;<br> private demoService dService;<br> private List&lt;Demo&gt; demos;<br> <br> public Demo getDemo() {<br>  return demo;<br> }<br> public void setDemo(Demo demo) {<br>  this.demo = demo;<br> }<br> public demoService getdService() {<br>  return dService;<br> }<br> public void setdService(demoService dService) {<br>  this.dService = dService;<br> }<br> public List&lt;Demo&gt; getDemos() {<br>  return demos;<br> }</p> <p> public void setDemos(List&lt;Demo&gt; demos) {<br>  this.demos = demos;<br> }<br> <br> public String execute(){<br>  return "index";<br> }</p> <p> public String index(){<br>  //demos=dService.getDemos(dService.createHql(demo),null);<br>  demos=dService.getDemos();<br>  return "index";<br> }<br> public String add(){<br>  return "add";<br> }<br> public String operate(){<br>  demo=dService.findByPrimaryKey(Demo.class,demo.getId());<br>  return "operate";<br> }<br> public String save(){<br>  dService.save(demo);<br>  return "save";<br> }<br> public String delete(){<br>  demo=dService.findByPrimaryKey(Demo.class,demo.getId());<br>  dService.delete(demo);<br>  return "delete";<br> }<br> public String update(){<br>  demo=dService.findByPrimaryKey(Demo.class,demo.getId());<br>  demo.setName(demo.getName());<br>  demo.setAge(demo.getAge());<br>  demo.setAddress(demo.getAddress());<br>  dService.update(demo);<br>  return "update";<br> }<br>}</p> <p> 实体:</p> <p>package com.demo.model;</p> <p>public class Demo {</p> <p> private Long id;<br> private String name;<br> private Integer age;<br> private String address;<br> <br> public Long getId() {<br>  return id;<br> }<br> public void setId(Long id) {<br>  this.id = id;<br> }<br> public String getName() {<br>  return name;<br> }<br> public void setName(String name) {<br>  this.name = name;<br> }<br> public Integer getAge() {<br>  return age;<br> }<br> public void setAge(Integer age) {<br>  this.age = age;<br> }<br> public String getAddress() {<br>  return address;<br> }<br> public void setAddress(String address) {<br>  this.address = address;<br> }<br>}</p> <p>映射文件:demo.hbm.xml</p> <p>&lt;?xml version="1.0" encoding="utf-8"?&gt;<br>&lt;!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"<br>"<a href="http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd</a>"&gt;<br>&lt;!-- <br>    Mapping file autogenerated by MyEclipse Persistence Tools<br>--&gt;<br>&lt;hibernate-mapping package="com.demo.model"&gt;<br>    &lt;class name="Demo" table="tb_demo" catalog="example"&gt;<br>        &lt;id name="id" type="java.lang.Long"&gt;<br>            &lt;column name="id" /&gt;<br>            &lt;generator class="sequence"&gt;<br>             &lt;param name="sequence"&gt;seq_demo&lt;/param&gt;<br>            &lt;/generator&gt;<br>        &lt;/id&gt;<br>        &lt;property name="name" type="java.lang.String"&gt;<br>            &lt;column name="tb_name" length="50" not-null="true" unique="true" /&gt;<br>        &lt;/property&gt;<br>        &lt;property name="age" type="java.lang.Integer"&gt;<br>            &lt;column name="tb_age" /&gt;<br>        &lt;/property&gt;<br>        &lt;property name="address" type="java.lang.String"&gt;<br>            &lt;column name="tb_address" length="50" not-null="true" /&gt;<br>        &lt;/property&gt;<br>    &lt;/class&gt;<br>&lt;/hibernate-mapping&gt;</p> <p> </p> <p>页面:</p> <p>demo-add.jsp  如下 :</p> <p>&lt;%@ page pageEncoding="utf-8" contentType="text/html; charset=utf-8"%&gt;<br>&lt;%@ taglib uri="/struts-tags" prefix="s"%&gt;<br>&lt;html&gt;<br> &lt;head&gt;<br>  &lt;title&gt;ssh整合测试&lt;/title&gt;<br>  &lt;script type="text/javascript" src="/SSH1/js/jquery.js"&gt;&lt;/script&gt;<br> &lt;/head&gt;<br> &lt;body&gt;<br>  &lt;form method="post" action="demo/demo.action"&gt;<br>  &lt;input type="hidden" id="num" name="demo.id" value="${demo.id}"/&gt;<br>   &lt;table&gt;<br>    &lt;tr&gt;ssh整合数据测试&lt;/tr&gt;<br>    &lt;tr&gt;&lt;td align="right"&gt;姓名:&lt;/td&gt;&lt;td align="left"&gt;&lt;input type="text" name="demo.name" value="${demo.name}"/&gt;&lt;/td&gt;&lt;/tr&gt;<br>    &lt;tr&gt;&lt;td align="right"&gt;年龄:&lt;/td&gt;&lt;td align="left"&gt;&lt;input type="text" name="demo.age" value="${demo.age}"/&gt;&lt;/td&gt;&lt;/tr&gt;<br>    &lt;tr&gt;&lt;td align="right"&gt;家庭住址:&lt;/td&gt;&lt;td align="left"&gt;&lt;input type="text" name="demo.address" value="${demo.address}"/&gt;&lt;/td&gt;&lt;/tr&gt;<br>    &lt;tr&gt;&lt;td colspan="2"&gt;&lt;input type="button" value="保存" id="save"/&gt;&lt;input type="reset" value="重置"/&gt;&lt;/td&gt;&lt;/tr&gt;<br>   &lt;/table&gt;<br>  &lt;/form&gt;<br> &lt;/body&gt;<br>&lt;/html&gt;<br>&lt;script&gt;<br> $("document").ready(function (){<br>  $("#save").click(function(){<br>   if($("#num").val()==null||$("#num").val()==""){<br>    document.forms[0].action="/SSH1/demo/demo!save.action";<br>    document.forms[0].submit();<br>   }else{<br>    alert("eee");<br>    document.forms[0].action="/SSH1/demo/demo!update.action";<br>    document.forms[0].submit();<br>   }<br>  });<br> });<br>&lt;/script&gt;</p> <p> </p> <p>demo-index.jsp  如下:</p> <p>&lt;%@ page pageEncoding="utf-8" contentType="text/html; charset=utf-8"%&gt;<br>&lt;%@ taglib uri="/struts-tags" prefix="s"%&gt;<br>&lt;html&gt;<br> &lt;head&gt;<br>  &lt;title&gt;ssh整合测试&lt;/title&gt;<br> &lt;/head&gt;<br> &lt;body&gt;<br>  &lt;form action="demo/demo.action"&gt;<br>   &lt;table&gt;<br>    &lt;tr&gt;&lt;td&gt;&lt;a href="&lt;%=request.getContextPath() %&gt;/demo/demo!add.action"&gt;添加&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;<br>    &lt;tr&gt;&lt;td&gt;序号&lt;/td&gt;&lt;td&gt;姓名&lt;/td&gt;&lt;td&gt;年龄&lt;/td&gt;&lt;td&gt;地址&lt;/td&gt;&lt;td&gt;操作&lt;/td&gt;&lt;/tr&gt;<br>    &lt;s:if test="demos.size()&gt;0"&gt;<br>     &lt;s:iterator value="demos" status="st"&gt;<br>      &lt;tr&gt;<br>       &lt;td&gt;${st.index+1}&lt;/td&gt;<br>       &lt;td&gt;${name}&lt;/td&gt;<br>       &lt;td&gt;${age}&lt;/td&gt;<br>       &lt;td&gt;${address}&lt;/td&gt;<br>       &lt;td&gt;&lt;a href="&lt;%=request.getContextPath() %&gt;/demo/demo!operate.action?demo.id=${id}"&gt;修改&lt;/a&gt;&amp;nbsp;&amp;nbsp;&lt;a href="&lt;%=request.getContextPath() %&gt;/demo/demo!operate.action?demo.id=${id}"&gt;删除&lt;/a&gt;&lt;/td&gt;<br>      &lt;/tr&gt;<br>     &lt;/s:iterator&gt;<br>    &lt;/s:if&gt;<br>   &lt;/table&gt;<br>  &lt;/form&gt;<br> &lt;/body&gt;<br>&lt;/html&gt;</p>
关于struts1多模块与spring注解
我使用switchAction来处理多模块请求, 想使用spring的注解来管理action, 在spring的配置文件中管理action是可以的,但是使用注解的则不行,不能创建action, 不知道是不是我的配置有问题,或者是有些什么其他的问题,希望哪位能帮我看看,解答一下 我的相关文件内容如下: web.xml [code="xml"] <servlet> <servlet-name>action</servlet-name> <servlet-class>org.apache.struts.action.ActionServlet</servlet-class> <init-param> <param-name>config</param-name> <param-value>/WEB-INF/struts/struts-config.xml</param-value> </init-param> <init-param> <param-name>config/demo</param-name> <param-value>/WEB-INF/struts/struts-config-demo.xml</param-value> </init-param> <init-param> <param-name>debug</param-name> <param-value>3</param-value> </init-param> <init-param> <param-name>detail</param-name> <param-value>3</param-value> </init-param> <load-on-startup>0</load-on-startup> </servlet> <servlet-mapping> <servlet-name>action</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping> [/code] struts-config.xml默认模块配置文件 [code="xml"] <action-mappings > <action path="/toModul" type="org.apache.struts.actions.SwitchAction"/> <action path="/demo"> <forward name="list" path="/WEB-INF/demo/demo.jsp"/> </action> </action-mappings> [/code] struts-config-demo.xml [code="xml"] <action-mappings > <action path="/demo"> <forward name="list" path="/../WEB-INF/demo1/demo1.jsp"/> </action> </action-mappings> [/code] Demo1Action [code="java"] @Controller("/demo1/demo") @Scope("prototype") public class Demo1Action extends DispatchAction { public ActionForward demo(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { request.setAttribute("message", "这是Demo1模块"); return mapping.findForward("list"); } [/code] DemoAction [code="java"] @Controller("/demo") @Scope("pototype") public class DemoAction extends DispatchAction { public ActionForward demo(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { request.setAttribute("message", "这是Demo模块"); return mapping.findForward("list"); } } [/code] applicationContext.xml [code="xml"] <!-- 这是我注释后的配置,如果不使用注解,使用这样的配置则是可以的 <bean name="/switch" class="org.apache.struts.actions.SwitchAction"/> <bean name="/demo/demo" class="com.wwq.web.demo1.action.Demo1Action"/> <bean name="/demo" class="com.wwq.web.demo.action.DemoAction"/> --> [/code] [b]问题补充:[/b] 忘了补充一点,我使用的是插件是 [code="xml"] <controller> <set-property property="processorClass" value="org.springframework.web.struts.DelegatingRequestProcessor"/> </controller> [/code] [quote] http://reack.itpub.net/post/1065/22126 蔡华江 (高级程序员) 2009-10-20 采纳为答案 举报作弊 [/quote] 谢谢蔡华江的回答,这个网址我刚才看过了,里面说的是不使用注解的方式来进行配置的,如果我不使用注解,而使用配置文件的话,是没有问题的,但是使用注解,再使用switchAction就不行了,我不知道是为什么, 报的错误是 HTTP Status 500 - No action instance for path /demo could be created 下面是我在jsp页面上写的访问路径 [code="html"] <a href="toModul.do?prefix=&page=/demo.do?action=demo">Demo</a> <a href="toModul.do?prefix=/demo&page=/demo.do?action=demo">Demo1</a> [/code] [b]问题补充:[/b] [quote]sunlightcs (高级程序员) 2009-10-22 [/quote] 谢谢你,你让我成功了一半,默认模块是没有问题了,但是我的那个demo子模块却不行,不知道为什么,希望能帮我解答,谢谢 [b]问题补充:[/b] [quote] 引用 @Controller("/demo1/demo") @Scope("prototype") public class Demo1Action extends DispatchAction { public ActionForward demo(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { request.setAttribute("message", "这是Demo1模块"); return mapping.findForward("list"); } 说明一点,不要@Controller("/demo1/demo") 这样写,"/demo1/demo"这是这个ACTION交给Spring管理时BEAN的名字,不是路径,最好这样写:@Controller("demo1Action") sunlightcs (高级程序员) 2009-10-23 采纳为答案 举报作弊 [/quote] 谢谢你的回答,我想再问一下: 如果说这里不写成/demo1/demo,难道这里不是需要和struts配置文件中的相匹配吗?在配置文件中配置的话,访问路径就是bean的name属性值,按说,这里应该也是没有错啊,还有,如果我这里不写成/demo1/demo,而直接写成/demo的话就会与默认模块的访问路径相冲突,刚试了一下,改为/demo1也不行,还是没有action实例被创建, [b]问题补充:[/b] [quote] sunlightcs (高级程序员) [/quote] 你说的是struts2.struts1不是这样的
struts2+spring+hibernate整合,spring出现问题.
<p>先看看我的配置文件:</p> <pre name="code" class="web.xml">&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;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"&gt; &lt;welcome-file-list&gt; &lt;welcome-file&gt;find.jsp&lt;/welcome-file&gt; &lt;/welcome-file-list&gt; &lt;filter&gt; &lt;filter-name&gt;struts2&lt;/filter-name&gt; &lt;filter-class&gt; org.apache.struts2.dispatcher.FilterDispatcher &lt;/filter-class&gt; &lt;/filter&gt; &lt;filter-mapping&gt; &lt;filter-name&gt;struts2&lt;/filter-name&gt; &lt;url-pattern&gt;/*&lt;/url-pattern&gt; &lt;/filter-mapping&gt; &lt;listener&gt; &lt;listener-class&gt; org.springframework.web.context.ContextLoaderListener &lt;/listener-class&gt; &lt;/listener&gt; &lt;context-param&gt; &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt; &lt;param-value&gt; classpath:applicationContext*.xml &lt;/param-value&gt; &lt;/context-param&gt; &lt;/web-app&gt;</pre> <p> </p> <pre name="code" class="struts.xml">&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"&gt; &lt;struts&gt; &lt;package name="eden" extends="struts-default"&gt; &lt;action name="selectBook" class="com.action.BookAction"&gt; &lt;result name="success"&gt;/index.jsp&lt;/result&gt; &lt;/action&gt; &lt;/package&gt; &lt;/struts&gt;</pre> <p> </p> <pre name="code" class="applicationContext.xml">&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd"&gt; &lt;bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"&gt; &lt;property name="configLocation" value="classpath:hibernate.cfg.xml"&gt; &lt;/property&gt; &lt;/bean&gt; &lt;bean id="BookDAO" class="com.dao.impl.BookDAO"&gt; &lt;property name="sessionFactory"&gt; &lt;ref bean="sessionFactory" /&gt; &lt;/property&gt; &lt;/bean&gt; &lt;bean id="BookService" class="com.service.impl.BookService"&gt; &lt;property name="bookDAO" ref="BookDAO"&gt;&lt;/property&gt; &lt;/bean&gt; &lt;bean id="BookAction" class="com.action.BookAction"&gt; &lt;property name="bookService" ref="BookService"&gt;&lt;/property&gt; &lt;/bean&gt; &lt;/beans&gt;</pre> <p> </p> <pre name="code" class="action类">package com.action; import java.util.List; import javax.servlet.http.HttpServletRequest; import org.apache.struts2.ServletActionContext; import com.entity.Book; import com.opensymphony.xwork2.ActionSupport; import com.service.IBookService; public class BookAction extends ActionSupport{ private IBookService BookService; private Book book; @Override public String execute() throws Exception { HttpServletRequest request = ServletActionContext.getRequest(); List&lt;Book&gt; bookItem = BookService.selectBookAll();//这行报空指针异常 System.out.println("List Size:" + bookItem.size()); request.setAttribute("bookItem", bookItem); return SUCCESS; } public Book getBook() { return book; } public void setBook(Book book) { this.book = book; } public IBookService getBookService() { return BookService; } public void setBookService(IBookService bookService) { BookService = bookService; } }</pre> <p> </p> <pre name="code" class="异常代码">2010-9-11 12:08:30 org.apache.catalina.core.StandardWrapperValve invoke 严重: Servlet.service() for servlet default threw exception java.lang.NullPointerException at com.action.BookAction.execute(BookAction.java:22) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:404) at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:267) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:229) at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:221) at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86) at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224) at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223) at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221) at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:150) at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:48) at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86) at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224) at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223) at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221) at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:123) at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224) at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223) at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221) at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:167) at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86) at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224) at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223) at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221) at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:105) at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224) at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223) at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221) at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:83) at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224) at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223) at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221) at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:207) at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224) at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223) at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221) at com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:74) at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224) at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223) at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221) at com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:127) at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224) at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223) at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221) at org.apache.struts2.interceptor.ProfilingActivationInterceptor.intercept(ProfilingActivationInterceptor.java:107) at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224) at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223) at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221) at org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:206) at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224) at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223) at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221) at com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:115) at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224) at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223) at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221) at com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:143) at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224) at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223) at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221) at com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:121) at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86) at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224) at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223) at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221) at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:170) at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224) at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223) at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221) at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:123) at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224) at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223) at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221) at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:176) at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224) at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223) at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221) at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:50) at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:504) at org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:419) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:261) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:581) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447) at java.lang.Thread.run(Unknown Source)</pre> <p> </p> <p>服务器启动时不会抛异常,在执行Action的时候,报空指针异常。说明在Action中的Service类没有注入成功。不知道是什么原因?</p>
关于Spring整合Struts采用监听器方式后,是否必须改写baseAction的问题.
&nbsp;&nbsp;&nbsp; 最近在javaeye看了很多Struts整合Spring的文章,之前虽然一直在使用SSH框架,但是在整合SSH框架方面,一直有个问题没有得到解决,那就是在采用以加载监听器方式整合的时候,为什么要在baseAction中写一个getBean方法. <br /> <br />=================================================================================== <br />配置方案一: 这是我在工程中正在使用的一种方式,也是我最关心的一种方式 <br />=================================================================================== <br />1.在web.xml中加载监听器 <br /><pre name="code" class="java"> &lt;listener&gt; &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt; &lt;/listener&gt; </pre> <br /> <br />2.在struts-config.xml中修改action的type类型为org.springframework.web.struts.DelegatingActionProxy <br />&nbsp; 使用委托方式,将struts中的Action配置到spring中,然后通过委托方式来调用Action <br /><pre name="code" class="java"> &lt;action path="/mouldFront/mainPageManager" scope="request" type="org.springframework.web.struts.DelegatingActionProxy" parameter="method"&gt; ....... &lt;forward name="index" path="/mouldFront/index.jsp"/&gt; ....... &lt;/action&gt; </pre> <br /> <br />3.在contextConfigLocation定义的配置文件中配置action需要的各种services <br /><pre name="code" class="java"> &lt;bean name="/mouldFront/mainPageManager" class="com.mould.web.front.actions.MainPageAction"&gt; ....... &lt;property name="infoService" ref="infoService"/&gt; ....... &lt;/bean&gt; </pre> <br /> <br />4.在baseAction中添加getBean方法. <br /><pre name="code" class="java"> public Object getBean(String name) { ApplicationContext ctx = WebApplicationContextUtils .getRequiredWebApplicationContext(servlet.getServletContext()); return ctx.getBean(name); } </pre> <br /> <br />我的疑惑是,既然已经使用了spring的IOC特性,在struts启动时ContextLoaderListener已经加载了上下文,而且我们已经将struts的action交给spring来管理,那我们为什么还要在baseaction中写这样的方法呢?我觉得这样做没有意义.不知道我理解对不对,希望能有熟悉的人来解释下.
struts2注解url没跳转到action里的方法,没报错也没跳转
我补下图片: ![图片说明](https://img-ask.csdn.net/upload/201509/21/1442781387_310218.png) package com.AppServer.action; import javax.annotation.Resource; import org.apache.struts2.convention.annotation.Action; import org.apache.struts2.convention.annotation.ExceptionMapping; import org.apache.struts2.convention.annotation.ExceptionMappings; import org.apache.struts2.convention.annotation.Namespace; import org.apache.struts2.convention.annotation.ParentPackage; import org.apache.struts2.convention.annotation.Result; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Controller; import org.springframework.stereotype.Service; import com.AppServer.bean.User; import com.AppServer.dao.UserDAO; import com.AppServer.service.UserService; import com.demo.interceptor.MethodCacheInterceptor; import com.opensymphony.xwork2.ActionSupport; import com.opensymphony.xwork2.ModelDriven; @Controller @ParentPackage("struts-default") @Namespace(value = "msgAction") @ExceptionMappings({ @ExceptionMapping(exception = "java.lange.RuntimeException", result = "error") }) public class MsgAction extends ActionSupport { private String username; private String password; @Resource private UserService userService; @Action(value = "msg" , results = { @Result(name = "success", location = "/success.jsp"), @Result(name = "failure", location = "/failure.jsp"), @Result(name = "error", location = "/login.jsp")}) //获取用户信息 public String getInfo() { System.out.println("进来玩"); return SUCCESS; } public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } } url访问如下:http://127.0.0.1:8080/AppServer_1.1/msgAction/msg.do 访问之后没报错,没进去getInfo这个方法 struts2.xml: <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN" "http://struts.apache.org/dtds/struts-2.3.dtd"> <struts> <!-- 指定Web应用的默认编码,相当于调用request的setCharacterEncoding方法 --> <constant name="struts.i18n.encoding" value="UTF-8" /> <!-- 设置浏览器是否缓存静态内容,默认值为true(生产环境下使用),开发阶段最好关闭 --> <constant name="struts.serve.static.browserCache" value="false" /> <!-- 当Struts2的配置文件修改后,系统是否自动重新加载配置文件,默认值为false(生产环境下使用),开发阶段最好打开 --> <constant name="struts.configuration.xml.reload" value="true" /> <!-- 开发模式下使用,这样可以打印出更详细的日志信息 --> <constant name="struts.devMode" value="true" /> <!-- 默认的视图主题 --> <constant name="struts.ui.theme" value="simple" /> <!-- 把Action对象交给Spring创建和管理 --> <constant name="struts.objectFactory" value="spring" /> <!-- Struts2处理的请求后缀,默认值是action --> <constant name="struts.action.extension" value="do" /> <!-- 国际化资源文件 <constant name="struts.custom.i18n.resources" value="globalMessages" /> --> <package name="msg" extends="struts-default"> <default-action-ref name="indexPage" /> <global-results> <result name="exceptionPage">/error/exceptionPage.jsp</result> </global-results> <global-exception-mappings> <exception-mapping result="exceptionPage" exception="java.lang.Exception" /> </global-exception-mappings> <action name="indexPage"> <result>/login.jsp</result> </action> <!-- <action name="msg" method="getInfo" class="com.AppServer.action.MsgAction"> <result name="success">/success.jsp</result> <result name="failure">/failure.jsp</result> <result name="error">/login.jsp</result> </action> --> </package> </struts> application.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:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd" default-autowire="byName" default-lazy-init="true"> <!-- 说明:下面有的Bean配置提供了多种方案,请根据需要采用某一种(别忘了注释掉其他同类方案) --> <!-- 自动扫描Spring注解配置 并保证@Required,@Autowired的属性被注入--> <context:component-scan base-package="com" /> <!-- 自动加载属性配置文件 --> <context:property-placeholder location="classpath:jdbc.properties" /> <!-- 配置数据源:方法一,使用C3P0方式(推荐) --> <!-- <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" --> <!-- destroy-method="close" --> <!-- p:driverClass="${jdbc.driverClassName}" --> <!-- p:jdbcUrl="${jdbc.url}" --> <!-- p:user="${jdbc.username}" --> <!-- p:password="${jdbc.password}" /> --> <!-- <context:property-placeholder location="classpath:jdbc.properties"/> --> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName" value="${jdbc.driverClassName}"/> <property name="url" value="${jdbc.url}"/> <property name="username" value="${jdbc.username}"/> <!-- property池启动时的初始值 --> <property name="password" value="${jdbc.password}"/> <!-- 连接name="initialSize" value="${initialSize}"/>--> <property name="initialSize" value="1"/> <!-- 连接池的最大值 --> <property name="maxActive" value="500"/> <!-- 最大空闲值.当经过一个高峰时间后,连接池可以慢慢将已经用不到的连接慢慢释放一部分,一直减少到maxIdle为止 --> <property name="maxIdle" value="2"/> <!-- 最小空闲值.当空闲的连接数少于阀值时,连接池就会预申请去一些连接,以免洪峰来时来不及申请 --> <property name="minIdle" value="1"/> </bean> <!-- 配置数据源:方法二,使用DBCP方式(不推荐) --> <!-- <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" p:driverClassName="${jdbc.driverClassName}" p:url="${jdbc.url}" p:username="${jdbc.username}" p:password="${jdbc.password}" /> --> <!-- 配置数据源:方法三,使用JNDI方式 --> <!-- <jee:jndi-lookup id="dataSource" jndi-name="${jndi.name}" /> --> <!-- 配置Hibernate的数据源代理工厂:方法一,使用p属性通配符,按文件名搜索匹配的映射文件 --> <!-- <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean" p:dataSource-ref="dataSource" > <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">${hibernate.dialect}</prop> <prop key="hibernate.show_sql">${hibernate.show_sql}</prop> <prop key="hibernate.format_sql">${hibernate.format_sql}</prop> <prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop> <prop key="hibernate.cache.use_second_level_cache">${hibernate.cache.use_second_level_cache}</prop> <prop key="hibernate.cache.use_query_cache">${hibernate.cache.use_query_cache}</prop> <prop key="hibernate.cache.region.factory_class">${hibernate.cache.region.factory_class}</prop> </props> </property> 加载hibernate的jpa注解形式实体 <property name="packagesToScan"> <list> <value>com.xmm.demo.domain*</value> </list> </property> </bean> --> <!-- 配置Hibernate的数据源代理工厂:方法二,使用list集合,按文件名搜索匹配的映射文件 --> <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean" p:dataSource-ref="dataSource"> <property name="mappingLocations"> <list> <value>classpath*:/com/**/*.hbm.xml</value> </list> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">${hibernate.dialect}</prop> <prop key="hibernate.show_sql">${hibernate.show_sql}</prop> <prop key="hibernate.format_sql">${hibernate.format_sql}</prop> <prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop> <prop key="hibernate.cache.use_second_level_cache">${hibernate.cache.use_second_level_cache}</prop> <prop key="hibernate.cache.use_query_cache">${hibernate.cache.use_query_cache}</prop> <prop key="hibernate.cache.region.factory_class">${hibernate.cache.region.factory_class}</prop> </props> </property> </bean> <!-- 配置Hibernate的数据源代理工厂:方法三,使用p属性通配符,按目录搜索映射文件 --> <!-- <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean" p:dataSource-ref="dataSource" p:mappingDirectoryLocations="classpath*:/com/**/domain"> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">${hibernate.dialect}</prop> <prop key="hibernate.show_sql">${hibernate.show_sql}</prop> <prop key="hibernate.format_sql">${hibernate.format_sql}</prop> <prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop> <prop key="hibernate.cache.use_second_level_cache">${hibernate.cache.use_second_level_cache}</prop> <prop key="hibernate.cache.use_query_cache">${hibernate.cache.use_query_cache}</prop> <prop key="hibernate.cache.region.factory_class">${hibernate.cache.region.factory_class}</prop> </props> </property> </bean> --> <!-- 配置Hibernate的数据源代理工厂:方法四,使用hibernate.cfg.xml --> <!-- <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean" p:dataSource-ref="dataSource" p:configLocation="classpath:hibernate.cfg.xml"> </bean> --> <!-- 配置事务管理器 --> <bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager" p:sessionFactory-ref="sessionFactory" /> <!-- 配置声明式事务:方法一,在Service实现类或者public实现方法上使用注解@Transactional,则此类或方法就会启用事务机制 --> <!-- <tx:annotation-driven transaction-manager="transactionManager" /> --> <!-- 配置声明式事务:方法二,使用tx/aop命名空间的配置(其实还有方法三,由于快要过时不推荐使用了,这里就不给出方法三的配置了) --> <tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="insert*" propagation="REQUIRED" /> <tx:method name="update*" propagation="REQUIRED" /> <tx:method name="edit*" propagation="REQUIRED" /> <tx:method name="save*" propagation="REQUIRED" /> <tx:method name="add*" propagation="REQUIRED" /> <tx:method name="new*" propagation="REQUIRED" /> <tx:method name="set*" propagation="REQUIRED" /> <tx:method name="remove*" propagation="REQUIRED" /> <tx:method name="delete*" propagation="REQUIRED" /> <tx:method name="change*" propagation="REQUIRED" /> <tx:method name="get*" propagation="REQUIRED" read-only="true" /> <tx:method name="find*" propagation="REQUIRED" read-only="true" /> <tx:method name="load*" propagation="REQUIRED" read-only="true" /> <tx:method name="search*" propagation="REQUIRED" read-only="true" /> <tx:method name="*" propagation="REQUIRED" read-only="true" /> </tx:attributes> </tx:advice> <aop:config> <aop:pointcut id="mypointcut" expression="execution(* com.**.service..*.*(..))" /> <aop:advisor advice-ref="txAdvice" pointcut-ref="mypointcut" /> </aop:config> <!-- 下面三个Bean的配置可有可无,但配置后用处更大,通常用于BaseDao类、其他Dao类或特殊工具类中 --> <bean id="hibernateTemplate" class="org.springframework.orm.hibernate4.HibernateTemplate" p:sessionFactory-ref="sessionFactory" /> <bean id="hibernateDaoSupport" class="org.springframework.orm.hibernate4.support.HibernateDaoSupport" p:hibernateTemplate-ref="hibernateTemplate" abstract="true"/> <bean id="sessionFactoryUtils" class="org.springframework.orm.hibernate4.SessionFactoryUtils" abstract="true"/> </beans> tomcat6.0:服务器运行正常: 九月 21, 2015 4:22:24 上午 org.apache.catalina.core.AprLifecycleListener init 信息: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: D:\Java\jdk1.7.0\bin;E:\tomcat6\bin 九月 21, 2015 4:22:25 上午 org.apache.coyote.http11.Http11Protocol init 信息: Initializing Coyote HTTP/1.1 on http-8080 九月 21, 2015 4:22:25 上午 org.apache.catalina.startup.Catalina load 信息: Initialization processed in 516 ms 九月 21, 2015 4:22:25 上午 org.apache.catalina.core.StandardService start 信息: Starting service Catalina 九月 21, 2015 4:22:25 上午 org.apache.catalina.core.StandardEngine start 信息: Starting Servlet Engine: Apache Tomcat/6.0.41 九月 21, 2015 4:22:25 上午 org.apache.catalina.startup.HostConfig deployDirectory 信息: Deploying web application directory AppServer_1.1 九月 21, 2015 4:22:25 上午 org.apache.catalina.loader.WebappClassLoader validateJarFile 信息: validateJarFile(E:\tomcat6\webapps\AppServer_1.1\WEB-INF\lib\servlet-api.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class 九月 21, 2015 4:22:26 上午 org.apache.catalina.core.ApplicationContext log 信息: Set web app root system property: 'webapp.root' = [E:\tomcat6\webapps\AppServer_1.1\] 九月 21, 2015 4:22:26 上午 org.apache.catalina.core.ApplicationContext log 信息: Initializing log4j from [classpath:log4j.properties] 九月 21, 2015 4:22:26 上午 org.apache.catalina.core.ApplicationContext log 信息: Initializing Spring root WebApplicationContext 九月 21, 2015 4:22:34 上午 org.apache.coyote.http11.Http11Protocol start 信息: Starting Coyote HTTP/1.1 on http-8080 九月 21, 2015 4:22:34 上午 org.apache.jk.common.ChannelSocket init 信息: JK: ajp13 listening on /0.0.0.0:8009 九月 21, 2015 4:22:34 上午 org.apache.jk.server.JkMain start 信息: Jk running ID=0 time=0/23 config=null 九月 21, 2015 4:22:34 上午 org.apache.catalina.startup.Catalina start 信息: Server startup in 9364 ms 测试定时任务:2015-09-21 04:30:00:074 测试定时任务:2015-09-21 04:40:00:004 url访问地址:http://127.0.0.1:8080/AppServer_1.1/msgAction/msg.do 没有进去action的getinfo方法,这是为什么?而且也没有任何的报错!!!!!!!!!!!
在中国程序员是青春饭吗?
今年,我也32了 ,为了不给大家误导,咨询了猎头、圈内好友,以及年过35岁的几位老程序员……舍了老脸去揭人家伤疤……希望能给大家以帮助,记得帮我点赞哦。 目录: 你以为的人生 一次又一次的伤害 猎头界的真相 如何应对互联网行业的「中年危机」 一、你以为的人生 刚入行时,拿着傲人的工资,想着好好干,以为我们的人生是这样的: 等真到了那一天,你会发现,你的人生很可能是这样的: ...
《MySQL 性能优化》之理解 MySQL 体系结构
本文介绍 MySQL 的体系结构,包括物理结构、逻辑结构以及插件式存储引擎。
程序员请照顾好自己,周末病魔差点一套带走我。
程序员在一个周末的时间,得了重病,差点当场去世,还好及时挽救回来了。
Python+OpenCV实时图像处理
目录 1、导入库文件 2、设计GUI 3、调用摄像头 4、实时图像处理 4.1、阈值二值化 4.2、边缘检测 4.3、轮廓检测 4.4、高斯滤波 4.5、色彩转换 4.6、调节对比度 5、退出系统 初学OpenCV图像处理的小伙伴肯定对什么高斯函数、滤波处理、阈值二值化等特性非常头疼,这里给各位分享一个小项目,可通过摄像头实时动态查看各类图像处理的特点,也可对各位调参、测试...
2020年一线城市程序员工资大调查
人才需求 一线城市共发布岗位38115个,招聘120827人。 其中 beijing 22805 guangzhou 25081 shanghai 39614 shenzhen 33327 工资分布 2020年中国一线城市程序员的平均工资为16285元,工资中位数为14583元,其中95%的人的工资位于5000到20000元之间。 和往年数据比较: yea...
为什么猝死的都是程序员,基本上不见产品经理猝死呢?
相信大家时不时听到程序员猝死的消息,但是基本上听不到产品经理猝死的消息,这是为什么呢? 我们先百度搜一下:程序员猝死,出现将近700多万条搜索结果: 搜索一下:产品经理猝死,只有400万条的搜索结果,从搜索结果数量上来看,程序员猝死的搜索结果就比产品经理猝死的搜索结果高了一倍,而且从下图可以看到,首页里面的五条搜索结果,其实只有两条才是符合条件。 所以程序员猝死的概率真的比产品经理大,并不是错...
害怕面试被问HashMap?这一篇就搞定了!
声明:本文以jdk1.8为主! 搞定HashMap 作为一个Java从业者,面试的时候肯定会被问到过HashMap,因为对于HashMap来说,可以说是Java集合中的精髓了,如果你觉得自己对它掌握的还不够好,我想今天这篇文章会非常适合你,至少,看了今天这篇文章,以后不怕面试被问HashMap了 其实在我学习HashMap的过程中,我个人觉得HashMap还是挺复杂的,如果真的想把它搞得明明白...
毕业5年,我问遍了身边的大佬,总结了他们的学习方法
我问了身边10个大佬,总结了他们的学习方法,原来成功都是有迹可循的。
python爬取百部电影数据,我分析出了一个残酷的真相
2019年就这么匆匆过去了,就在前几天国家电影局发布了2019年中国电影市场数据,数据显示去年总票房为642.66亿元,同比增长5.4%;国产电影总票房411.75亿元,同比增长8.65%,市场占比 64.07%;城市院线观影人次17.27亿,同比增长0.64%。 看上去似乎是一片大好对不对?不过作为一名严谨求实的数据分析师,我从官方数据中看出了一点端倪:国产票房增幅都已经高达8.65%了,为什...
推荐10个堪称神器的学习网站
每天都会收到很多读者的私信,问我:“二哥,有什么推荐的学习网站吗?最近很浮躁,手头的一些网站都看烦了,想看看二哥这里有什么新鲜货。” 今天一早做了个恶梦,梦到被老板辞退了。虽然说在我们公司,只有我辞退老板的份,没有老板辞退我这一说,但是还是被吓得 4 点多都起来了。(主要是因为我掌握着公司所有的核心源码,哈哈哈) 既然 4 点多起来,就得好好利用起来。于是我就挑选了 10 个堪称神器的学习网站,推...
这些软件太强了,Windows必装!尤其程序员!
Windows可谓是大多数人的生产力工具,集娱乐办公于一体,虽然在程序员这个群体中都说苹果是信仰,但是大部分不都是从Windows过来的,而且现在依然有很多的程序员用Windows。 所以,今天我就把我私藏的Windows必装的软件分享给大家,如果有一个你没有用过甚至没有听过,那你就赚了????,这可都是提升你幸福感的高效率生产力工具哦! 走起!???? NO、1 ScreenToGif 屏幕,摄像头和白板...
阿里面试,面试官没想到一个ArrayList,我都能跟他扯半小时
我是真的没想到,面试官会这样问我ArrayList。
曾经优秀的人,怎么就突然不优秀了。
职场上有很多辛酸事,很多合伙人出局的故事,很多技术骨干被裁员的故事。说来模板都类似,曾经是名校毕业,曾经是优秀员工,曾经被领导表扬,曾经业绩突出,然而突然有一天,因为种种原因,被裁员了,...
C语言荣获2019年度最佳编程语言
关注、星标公众号,不错过精彩内容作者:黄工公众号:strongerHuang近日,TIOBE官方发布了2020年1月编程语言排行榜单。我在前面给过一篇文章《2019年11月C语言接近Ja...
大学四年因为知道了这32个网站,我成了别人眼中的大神!
依稀记得,毕业那天,我们导员发给我毕业证的时候对我说“你可是咱们系的风云人物啊”,哎呀,别提当时多开心啦????,嗯,我们导员是所有导员中最帅的一个,真的???? 不过,导员说的是实话,很多人都叫我大神的,为啥,因为我知道这32个网站啊,你说强不强????,这次是绝对的干货,看好啦,走起来! PS:每个网站都是学计算机混互联网必须知道的,真的牛杯,我就不过多介绍了,大家自行探索,觉得没用的,尽管留言吐槽吧???? 社...
良心推荐,我珍藏的一些Chrome插件
上次搬家的时候,发了一个朋友圈,附带的照片中不小心暴露了自己的 Chrome 浏览器插件之多,于是就有小伙伴评论说分享一下我觉得还不错的浏览器插件。 我下面就把我日常工作和学习中经常用到的一些 Chrome 浏览器插件分享给大家,随便一个都能提高你的“生活品质”和工作效率。 Markdown Here Markdown Here 可以让你更愉快的写邮件,由于支持 Markdown 直接转电子邮...
看完这篇HTTP,跟面试官扯皮就没问题了
我是一名程序员,我的主要编程语言是 Java,我更是一名 Web 开发人员,所以我必须要了解 HTTP,所以本篇文章就来带你从 HTTP 入门到进阶,看完让你有一种恍然大悟、醍醐灌顶的感觉。 最初在有网络之前,我们的电脑都是单机的,单机系统是孤立的,我还记得 05 年前那会儿家里有个电脑,想打电脑游戏还得两个人在一个电脑上玩儿,及其不方便。我就想为什么家里人不让上网,我的同学 xxx 家里有网,每...
史上最全的IDEA快捷键总结
现在Idea成了主流开发工具,这篇博客对其使用的快捷键做了总结,希望对大家的开发工作有所帮助。
阿里程序员写了一个新手都写不出的低级bug,被骂惨了。
这种新手都不会范的错,居然被一个工作好几年的小伙子写出来,差点被当场开除了。
谁是华为扫地僧?
是的,华为也有扫地僧!2020年2月11-12日,“养在深闺人不知”的华为2012实验室扫地僧们,将在华为开发者大会2020(Cloud)上,和大家见面。到时,你可以和扫地僧们,吃一个洋...
AI 没让人类失业,搞 AI 的人先失业了
最近和几个 AI 领域的大佬闲聊 根据他们讲的消息和段子 改编出下面这个故事 如有雷同 都是巧合 1. 老王创业失败,被限制高消费 “这里写我跑路的消息实在太夸张了。” 王葱葱哼笑一下,把消息分享给群里。 阿杰也看了消息,笑了笑。在座几位也都笑了。 王葱葱是个有名的人物,21岁那年以全额奖学金进入 KMU 攻读人工智能博士,累计发表论文 40 余篇,个人技术博客更是成为深度学习领域内风向标。 ...
2020年,冯唐49岁:我给20、30岁IT职场年轻人的建议
点击“技术领导力”关注∆每天早上8:30推送 作者|Mr.K 编辑| Emma 来源|技术领导力(ID:jishulingdaoli) 前天的推文《冯唐:职场人35岁以后,方法论比经验重要》,收到了不少读者的反馈,觉得挺受启发。其实,冯唐写了不少关于职场方面的文章,都挺不错的。可惜大家只记住了“春风十里不如你”、“如何避免成为油腻腻的中年人”等不那么正经的文章。 本文整理了冯...
一份王者荣耀的英雄数据报告
咪哥杂谈本篇阅读时间约为 6 分钟。1前言前一阵写了关于王者的一些系列文章,从数据的获取到数据清洗,数据落地,都是为了本篇的铺垫。今天来实现一下,看看不同维度得到的结论。2环境准备本次实...
作为一名大学生,如何在B站上快乐的学习?
B站是个宝,谁用谁知道???? 作为一名大学生,你必须掌握的一项能力就是自学能力,很多看起来很牛X的人,你可以了解下,人家私底下一定是花大量的时间自学的,你可能会说,我也想学习啊,可是嘞,该学习啥嘞,不怕告诉你,互联网时代,最不缺的就是学习资源,最宝贵的是啥? 你可能会说是时间,不,不是时间,而是你的注意力,懂了吧! 那么,你说学习资源多,我咋不知道,那今天我就告诉你一个你必须知道的学习的地方,人称...
那些年,我们信了课本里的那些鬼话
教材永远都是有错误的,从小学到大学,我们不断的学习了很多错误知识。 斑羚飞渡 在我们学习的很多小学课文里,有很多是错误文章,或者说是假课文。像《斑羚飞渡》: 随着镰刀头羊的那声吼叫,整个斑羚群迅速分成两拨,老年斑羚为一拨,年轻斑羚为一拨。 就在这时,我看见,从那拨老斑羚里走出一只公斑羚来。公斑羚朝那拨年轻斑羚示意性地咩了一声,一只半大的斑羚应声走了出来。一老一少走到伤心崖,后退了几步,突...
一个程序在计算机中是如何运行的?超级干货!!!
强烈声明:本文很干,请自备茶水!???? 开门见山,咱不说废话! 你有没有想过,你写的程序,是如何在计算机中运行的吗?比如我们搞Java的,肯定写过这段代码 public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } ...
【蘑菇街技术部年会】程序员与女神共舞,鼻血再次没止住。(文末内推)
蘑菇街技术部的年会,别开生面,一样全是美女。
那个在阿里养猪的工程师,5年了……
简介: 在阿里,走过1825天,没有趴下,依旧斗志满满,被称为“五年陈”。他们会被授予一枚戒指,过程就叫做“授戒仪式”。今天,咱们听听阿里的那些“五年陈”们的故事。 下一个五年,猪圈见! 我就是那个在养猪场里敲代码的工程师,一年多前我和20位工程师去了四川的猪场,出发前总架构师慷慨激昂的说:同学们,中国的养猪产业将因为我们而改变。但到了猪场,发现根本不是那么回事:要个WIFI,没有;...
为什么程序猿都不愿意去外包?
分享外包的组织架构,盈利模式,亲身经历,以及根据一些外包朋友的反馈,写了这篇文章 ,希望对正在找工作的老铁有所帮助
Java校招入职华为,半年后我跑路了
何来 我,一个双非本科弟弟,有幸在 19 届的秋招中得到前东家华为(以下简称 hw)的赏识,当时秋招签订就业协议,说是入了某 java bg,之后一系列组织架构调整原因等等让人无法理解的神操作,最终毕业前夕,被通知调往其他 bg 做嵌入式开发(纯 C 语言)。 由于已至于校招末尾,之前拿到的其他 offer 又无法再收回,一时感到无力回天,只得默默接受。 毕业后,直接入职开始了嵌入式苦旅,由于从未...
立即提问