刚学Struts2,访问index.jsp页面正常,访问login.jsp页面就报错

我用的是通配符的方式访问,输入
http://localhost:8088/TestStruts/TestStruts_index.action时可以跳转到index.jsp页面,
但输入http://localhost:8088/TestStruts/TestStruts_login.action时,
就报There is no Action mapped for namespace [/] and action name [TestStruts_login] associated with context path [/TestStruts].

struts.xml代码如下:

<?xml version="1.0" encoding="UTF-8" ?>

<!DOCTYPE struts PUBLIC

"-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"

"http://struts.apache.org/dtds/struts-2.5.dtd">


<constant name="struts.i18n.encoding" value="UTF-8"></constant>

<constant name="struts.action.extension" value="do,action"></constant>

<constant name="struts.serve.static.browserCache" value="false"></constant>

<constant name="struts.configuration.xml.reload" value="true"></constant>

<constant name="struts.devMode" value="true"></constant>

<constant name="struts.enable.DynamicMethodInvocation" value="false"></constant>


<package name="default" namespace="/" extends="struts-default">
    <action name="*_*" method="{2}" class="com.test.action.{1}" >
        <result name="login">/login.jsp</result>
        <result name="index">/{2}.jsp</result>
    </action>


</package>

麻烦大神解惑~

5个回答

问题已解决,应该是Struts2版本问题,把原来的

加上一句strict-method-invocation="false",就可以了

谢谢楼上的解答,虽然还没看^_^

恩?怎么代码出不来,就是在struts.xml的package加一句strict-method-invocation="false",即

对了我的Struts2版本是2.5.5的,有碰上这个问题的朋友可以参考下

struts2好像由于安全问题用的不多了,不过学习框架入门还是很有必要的

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
这个是我访问login.jsp页面出项的问题麻烦高手看看
org.apache.jasper.JasperException: javax.servlet.ServletException: javax.servlet.jsp.JspException: Cannot find ActionMappings or ActionFormBeans collection org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:491) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:401) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260) javax.servlet.http.HttpServlet.service(HttpServlet.java:717) org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:413) root cause javax.servlet.ServletException: javax.servlet.jsp.JspException: Cannot find ActionMappings or ActionFormBeans collection org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:862) org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:791) org.apache.jsp.login_jsp._jspService(login_jsp.java:101) org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) javax.servlet.http.HttpServlet.service(HttpServlet.java:717) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260) javax.servlet.http.HttpServlet.service(HttpServlet.java:717) org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:413) root cause javax.servlet.jsp.JspException: Cannot find ActionMappings or ActionFormBeans collection org.apache.struts.taglib.html.FormTag.lookup(FormTag.java:747) org.apache.struts.taglib.html.FormTag.doStartTag(FormTag.java:443) org.apache.jsp.login_jsp._jspx_meth_html_005fform_005f0(login_jsp.java:120) org.apache.jsp.login_jsp._jspService(login_jsp.java:88) org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) javax.servlet.http.HttpServlet.service(HttpServlet.java:717) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260) javax.servlet.http.HttpServlet.service(HttpServlet.java:717) org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:413) 是哪里出了问题 这个是我struts.xml <action name="login" class="loginAction" method="login"> <result>/index.jsp</result> <result name="put">/login.jsp</result> </action> 这个是我Action public String login() { System.out.println("---->jinlai lma"); longinservice.valid(users); return SUCCESS; } 这个是我spring.xml <bean id="loginDAOImpl" class="org.shj.houseproject.login.dao.LoginDAOImpl"> <property name="sessionFactory"> <ref bean="sessionFactory"/> </property> </bean> <!-- 将loginDAO注入到logindaoserviceImpl中 --> <bean id="loginManager" class="org.shj.houseproject.loginService.LoginServiceImpl"> <property name="logindaoi"> <ref bean="loginDAOImpl"/> </property> </bean> <!-- 将loginserviceImpl注入到Action --> <bean id="loginAction" class="org.shj.houseproject.login.action.LoginAction"> <property name="longinservice"> <ref bean="loginManager" />
struts2异常java.lang.NoSuchMethodException: com.struts.action.UserAction.create()
原来用的struts2.0版本,运行项目没有问题。后来换了struts2.2.1版本后,只要访问Action,都会出现 java.lang.NoSuchMethodException: com.struts.action.UserAction.create()类似的错误,就是说Action中找不到create这个方法。 struts.xml [code="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> <include file="defaults.xml"></include> <package name="struts.action.user" namespace="/user" extends="struts-default"> <interceptors> <interceptor name="loginInterceptor" class="com.innoact.struts.interceptor.LoginInterceptor"> </interceptor> </interceptors> <action name="user_*" class="com.innoact.struts.action.UserAction" method="{1}"> <interceptor-ref name="loginInterceptor"> <param name="excludeMethods">login,register</param> <param name="includeMethods">update</param> </interceptor-ref> <interceptor-ref name="defaultStack"></interceptor-ref> <result name="success">/main.jsp</result> <result name="login">/index.jsp</result> </action> </package> </struts> [/code] 我设定的是方法拦截,所以当进入user_update.action的时候,没有问题,因为它可以进入拦截器。但是我没有拦截login和register方法,进入这两个方法时就会出错。说找不到create方法。我Action里面没有这个方法,肯定找不到。而且继承的ActionSupport的里面也没有这个方法,只有excute方法。不知道为什么struts会非要找这个create方法!后来上网查了半天,人家说去掉<include file="defaults.xml"></include>这部分就可以。 defaults.xml [code="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> <package name="defaults" extends="struts-default"> <global-results> <result name="error">/error.jsp</result> </global-results> <global-exception-mappings> <exception-mapping exception="java.lang.NullPointerException" result="error" /> <exception-mapping exception="java.lang.Exception" result="error" /> </global-exception-mappings> </package> </struts> [/code] 试了下,果然奏效。但是用原来struts2.0的版本没有这样的问题啊!不知道为什么,哪位高人来解释下,感激不尽!最好能带 struts的源代码分析下!还有struts2.0和2.1之后的地方,有哪些区别? Oh My God!现在又不行了。不知道是不是我刚才手动加的create方法没去掉,现在又报这个错误,蛋疼啊!高手速来解答!感激不尽啊!
struts2.5.8动态方法调用使用通配符无效
我在使用struts2.5.8时,在jsp页面中: ```jsp <s:form namespace="/zzw" action="login"> <s:textfield name="username" key="username"/> <s:textfield name="password" key="password"/> <s:submit key="login" action="login_login"/> <s:submit key="register" action="login_register"/> </s:form> ``` 在struts.xml中: ```xml <constant name="struts.enable.DynamicMethodInvocation" value="false"/> <package name="zzw" extends="struts-default" namespace="/zzw" strict-method-invocation="false"> <global-allowed-methods>regex:.*</global-allowed-methods> <action name="login_*" class="com.zzw.action.LoginAction"> <result name="success">/result.jsp</result> </action> </package> ``` 结果是点击jsp页面的登录/注册页面,跳转到了LoginAction,但没有调用相应的方法(login或register),求大神帮下忙,谢谢!
想整合struts2.2.1与spring3.1.0,出现了一点麻烦,请各位给点建议,谢谢关注
<pre name="code" class="xml"> &lt;bean id="loginDao" class="com.test.dao.login.impl.LoginDaoImpl"/&gt; &lt;bean id="loginService" class = "com.test.service.impl.LoginServiceImpl" scope="prototype"&gt; &lt;property name="loginDao"&gt; &lt;ref bean = "loginDao"/&gt; &lt;/property&gt; &lt;/bean&gt; &lt;bean id="loginActionBean" class="com.test.action.LoginAction" scope="prototype"&gt; &lt;property name="loginService"&gt; &lt;ref bean = "loginService"/&gt; &lt;/property&gt; &lt;/bean&gt;</pre> <p> 上面是applicationContext.xml的配置。</p> <p> </p> <pre name="code" class="java">package com.test.action; import com.test.base.BaseAction; import com.test.service.LoginService; public class LoginAction extends BaseAction{ private String userName = null; private String password = null; private LoginService loginService; public LoginService getLoginService() { return loginService; } public void setLoginService(LoginService loginService) { this.loginService = loginService; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public String getUserName() { return userName; } public void setUserName(String userName) { this.userName = userName; } public String execute() throws Exception { System.out.println("=========用户民:"+getUserName()); System.out.println("=========密 码:"+getPassword()); return loginService.login(getUserName(),getPassword()); } }</pre> <p> 上面是action的代码</p> <p> </p> <pre name="code" class="java">public interface LoginDao { public String login(String userName, String password); }</pre> <p>上面是loginDao接口。</p> <p> </p> <p> </p> <pre name="code" class="java">public class LoginDaoImpl extends BaseAction implements LoginDao{ public String login(String userName, String password) { if(isInvalid(userName)||isInvalid(password)){ return LOGIN; }else if(userName.equals("Tom") &amp;&amp; password.equals("123456")){ return SUCCESS; }else{ return LOGIN; } } }</pre> <p>上面是logiDao的实现类LoginDaoImpl。</p> <p> </p> <pre name="code" class="java">public interface LoginService{ public abstract String login(String userName, String password); }</pre> <p>上面是loginService接口。</p> <p> </p> <pre name="code" class="java">public class LoginServiceImpl implements LoginService{ LoginDao dao; public LoginServiceImpl(LoginDao dao){ this.dao = dao; } public String login(String userName, String password){ return this.dao.login(userName, password); } }</pre> <p> 上面是loginService的实现类LoginServiceImpl。</p> <p> </p> <p>基于上述代码运行后,会报出以下异常:</p> <p> </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 org.apache.jasper.JasperException: java.lang.NullPointerException org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:522) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:416) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267) javax.servlet.http.HttpServlet.service(HttpServlet.java:717) org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:88) root cause java.lang.NullPointerException org.apache.struts2.components.UIBean.evaluateParams(UIBean.java:792) org.apache.struts2.components.UIBean.end(UIBean.java:510) org.apache.struts2.views.jsp.ComponentTagSupport.doEndTag(ComponentTagSupport.java:42) org.apache.jsp.login_jsp._jspx_meth_s_005ftextfield_005f0(login_jsp.java:185) org.apache.jsp.login_jsp._jspx_meth_s_005fform_005f0(login_jsp.java:141) org.apache.jsp.login_jsp._jspService(login_jsp.java:78) org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) javax.servlet.http.HttpServlet.service(HttpServlet.java:717) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267) javax.servlet.http.HttpServlet.service(HttpServlet.java:717) org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:88) </pre> <p> </p> <p>jdk控制台的打印信息如下:</p> <p> </p> <pre name="code" class="c">2011-4-17 11:48:21 com.opensymphony.xwork2.util.logging.commons.CommonsLogger er ror 严重: Could not open template org.springframework.beans.factory.BeanCreationException: Error creating bean wit h name 'loginActionBean' defined in file [D:\workspace\test\WebContent\WEB-IN F\classes\applicationContext.xml]: Cannot resolve reference to bean 'loginServic e' while setting bean property 'loginService'; nested exception is org.springfra mework.beans.factory.BeanCreationException: Error creating bean with name 'login Service' defined in file [D:\workspace\test\WebContent\WEB-INF\classes\applic ationContext.xml]: Instantiation of bean failed; nested exception is org.springf ramework.beans.BeanInstantiationException: Could not instantiate bean class [com .test.service.impl.LoginServiceImpl]: No default constructor found; nested ex ception is java.lang.NoSuchMethodException: com.test.service.impl.LoginServic eImpl.&lt;init&gt;() at org.springframework.beans.factory.support.BeanDefinitionValueResolver .resolveReference(BeanDefinitionValueResolver.java:328) at org.springframework.beans.factory.support.BeanDefinitionValueResolver .resolveValueIfNecessary(BeanDefinitionValueResolver.java:106) at org.springframework.beans.factory.support.AbstractAutowireCapableBean Factory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1325) at org.springframework.beans.factory.support.AbstractAutowireCapableBean Factory.populateBean(AbstractAutowireCapableBeanFactory.java:1086) at org.springframework.beans.factory.support.AbstractAutowireCapableBean Factory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517) at org.springframework.beans.factory.support.AbstractAutowireCapableBean Factory.createBean(AbstractAutowireCapableBeanFactory.java:456) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBe an(AbstractBeanFactory.java:314) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean (AbstractBeanFactory.java:194) at org.springframework.context.support.AbstractApplicationContext.getBea n(AbstractApplicationContext.java:1080) at com.opensymphony.xwork2.spring.SpringObjectFactory.getClassInstance(S pringObjectFactory.java:221) at org.apache.struts2.components.ServletUrlRenderer.renderFormUrl(Servle tUrlRenderer.java:161) at org.apache.struts2.components.Form.populateComponentHtmlId(Form.java: 220) at org.apache.struts2.components.UIBean.evaluateParams(UIBean.java:784) at org.apache.struts2.components.ClosingUIBean.start(ClosingUIBean.java: 57) at org.apache.struts2.views.jsp.ComponentTagSupport.doStartTag(Component TagSupport.java:53) at org.apache.jsp.login_jsp._jspx_meth_s_005fform_005f0(login_jsp.java:1 30) at org.apache.jsp.login_jsp._jspService(login_jsp.java:78) at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper .java:374) at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:3 42) at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267) at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl icationFilterChain.java:290) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF ilterChain.java:206) at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter .doFilter(StrutsPrepareAndExecuteFilter.java:88) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl icationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF ilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV alve.java:233) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV alve.java:191) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j ava:128) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j ava:102) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal ve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.jav a:293) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java :849) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.proce ss(Http11Protocol.java:583) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:45 4) at java.lang.Thread.run(Thread.java:619) Caused by: org.springframework.beans.factory.BeanCreationException: Error creati ng bean with name 'loginService' defined in file [D:\workspace\test\WebConten t\WEB-INF\classes\applicationContext.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not ins tantiate bean class [com.test.service.impl.LoginServiceImpl]: No default cons tructor found; nested exception is java.lang.NoSuchMethodException: com.test. service.impl.LoginServiceImpl.&lt;init&gt;() at org.springframework.beans.factory.support.AbstractAutowireCapableBean Factory.instantiateBean(AbstractAutowireCapableBeanFactory.java:965) at org.springframework.beans.factory.support.AbstractAutowireCapableBean Factory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:911) at org.springframework.beans.factory.support.AbstractAutowireCapableBean Factory.doCreateBean(AbstractAutowireCapableBeanFactory.java:485) at org.springframework.beans.factory.support.AbstractAutowireCapableBean Factory.createBean(AbstractAutowireCapableBeanFactory.java:456) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBe an(AbstractBeanFactory.java:314) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean (AbstractBeanFactory.java:194) at org.springframework.beans.factory.support.BeanDefinitionValueResolver .resolveReference(BeanDefinitionValueResolver.java:322) ... 37 more Caused by: org.springframework.beans.BeanInstantiationException: Could not insta ntiate bean class [com.test.service.impl.LoginServiceImpl]: No default constr uctor found; nested exception is java.lang.NoSuchMethodException: com.test.se rvice.impl.LoginServiceImpl.&lt;init&gt;() at org.springframework.beans.factory.support.SimpleInstantiationStrategy .instantiate(SimpleInstantiationStrategy.java:70) at org.springframework.beans.factory.support.AbstractAutowireCapableBean Factory.instantiateBean(AbstractAutowireCapableBeanFactory.java:958) ... 43 more Caused by: java.lang.NoSuchMethodException: com.test.service.impl.LoginServic eImpl.&lt;init&gt;() at java.lang.Class.getConstructor0(Class.java:2706) at java.lang.Class.getDeclaredConstructor(Class.java:1985) at org.springframework.beans.factory.support.SimpleInstantiationStrategy .instantiate(SimpleInstantiationStrategy.java:65) ... 44 more org.springframework.beans.factory.BeanCreationException: Error creating bean wit h name 'loginActionBean' defined in file [D:\workspace\test\WebContent\WEB-IN F\classes\applicationContext.xml]: Cannot resolve reference to bean 'loginServic e' while setting bean property 'loginService'; nested exception is org.springfra mework.beans.factory.BeanCreationException: Error creating bean with name 'login Service' defined in file [D:\workspace\test\WebContent\WEB-INF\classes\applic ationContext.xml]: Instantiation of bean failed; nested exception is org.springf ramework.beans.BeanInstantiationException: Could not instantiate bean class [com .test.service.impl.LoginServiceImpl]: No default constructor found; nested ex ception is java.lang.NoSuchMethodException: com.test.service.impl.LoginServic eImpl.&lt;init&gt;() at org.springframework.beans.factory.support.BeanDefinitionValueResolver .resolveReference(BeanDefinitionValueResolver.java:328) at org.springframework.beans.factory.support.BeanDefinitionValueResolver .resolveValueIfNecessary(BeanDefinitionValueResolver.java:106) at org.springframework.beans.factory.support.AbstractAutowireCapableBean Factory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1325) at org.springframework.beans.factory.support.AbstractAutowireCapableBean Factory.populateBean(AbstractAutowireCapableBeanFactory.java:1086) at org.springframework.beans.factory.support.AbstractAutowireCapableBean Factory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517) at org.springframework.beans.factory.support.AbstractAutowireCapableBean Factory.createBean(AbstractAutowireCapableBeanFactory.java:456) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBe an(AbstractBeanFactory.java:314) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean (AbstractBeanFactory.java:194) at org.springframework.context.support.AbstractApplicationContext.getBea n(AbstractApplicationContext.java:1080) at com.opensymphony.xwork2.spring.SpringObjectFactory.getClassInstance(S pringObjectFactory.java:221) at org.apache.struts2.components.ServletUrlRenderer.renderFormUrl(Servle tUrlRenderer.java:161) at org.apache.struts2.components.Form.populateComponentHtmlId(Form.java: 220) at org.apache.struts2.components.UIBean.evaluateParams(UIBean.java:784) at org.apache.struts2.components.ClosingUIBean.start(ClosingUIBean.java: 57) at org.apache.struts2.views.jsp.ComponentTagSupport.doStartTag(Component TagSupport.java:53) at org.apache.jsp.login_jsp._jspx_meth_s_005fform_005f0(login_jsp.java:1 30) at org.apache.jsp.login_jsp._jspService(login_jsp.java:78) at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper .java:374) at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:3 42) at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267) at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl icationFilterChain.java:290) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF ilterChain.java:206) at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter .doFilter(StrutsPrepareAndExecuteFilter.java:88) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl icationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF ilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV alve.java:233) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV alve.java:191) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j ava:128) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j ava:102) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal ve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.jav a:293) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java :849) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.proce ss(Http11Protocol.java:583) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:45 4) at java.lang.Thread.run(Thread.java:619) Caused by: org.springframework.beans.factory.BeanCreationException: Error creati ng bean with name 'loginService' defined in file [D:\workspace\test\WebConten t\WEB-INF\classes\applicationContext.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not ins tantiate bean class [com.test.service.impl.LoginServiceImpl]: No default cons tructor found; nested exception is java.lang.NoSuchMethodException: com.test. service.impl.LoginServiceImpl.&lt;init&gt;() at org.springframework.beans.factory.support.AbstractAutowireCapableBean Factory.instantiateBean(AbstractAutowireCapableBeanFactory.java:965) at org.springframework.beans.factory.support.AbstractAutowireCapableBean Factory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:911) at org.springframework.beans.factory.support.AbstractAutowireCapableBean Factory.doCreateBean(AbstractAutowireCapableBeanFactory.java:485) at org.springframework.beans.factory.support.AbstractAutowireCapableBean Factory.createBean(AbstractAutowireCapableBeanFactory.java:456) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBe an(AbstractBeanFactory.java:314) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean (AbstractBeanFactory.java:194) at org.springframework.beans.factory.support.BeanDefinitionValueResolver .resolveReference(BeanDefinitionValueResolver.java:322) ... 37 more Caused by: org.springframework.beans.BeanInstantiationException: Could not insta ntiate bean class [com.test.service.impl.LoginServiceImpl]: No default constr uctor found; nested exception is java.lang.NoSuchMethodException: com.test.se rvice.impl.LoginServiceImpl.&lt;init&gt;() at org.springframework.beans.factory.support.SimpleInstantiationStrategy .instantiate(SimpleInstantiationStrategy.java:70) at org.springframework.beans.factory.support.AbstractAutowireCapableBean Factory.instantiateBean(AbstractAutowireCapableBeanFactory.java:958) ... 43 more Caused by: java.lang.NoSuchMethodException: com.test.service.impl.LoginServic eImpl.&lt;init&gt;() at java.lang.Class.getConstructor0(Class.java:2706) at java.lang.Class.getDeclaredConstructor(Class.java:1985) at org.springframework.beans.factory.support.SimpleInstantiationStrategy .instantiate(SimpleInstantiationStrategy.java:65) ... 44 more </pre> <p> </p> <p>请各位高手看看,这是什么原因哈,struts2配置没有问题的,因为已经测试过了,struts.xml的配置如下:</p> <pre name="code" class="xml">&lt;struts&gt; &lt;package name="login" extends="struts-default"&gt; &lt;action name="login" class= "loginActionBean"&gt; &lt;result name="success"&gt;/success.jsp&lt;/result&gt; &lt;result name="login"&gt;/error.jsp&lt;/result&gt; &lt;/action&gt; &lt;!-- Add actions here --&gt; &lt;/package&gt; &lt;/struts&gt;</pre> <p> </p>
struts2中jsp页面参数不能传递给action
struts.xml: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <package name="default" extends="struts-default"> <action name="HelloWorld" class="org.sunxin.struts2.ch002.action.HelloWorldAction"> <result name="SUCCESS">/HelloWorld.jsp</result> </action> <action name="login" class="org.sunxin.struts2.ch002.action.LoginAction"> <result name="ok">/succes.jsp</result> <result name="error">/error.jsp</result> </action> </package> </struts> web.xml: <?xml version="1.0" encoding="UTF-8"?> <web-app version="3.0" 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_3_0.xsd"> <display-name></display-name> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <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> </web-app> login.jsp: <%@ page contentType="text/html; charset=utf-8"%> <%@ taglib prefix="s" uri="/struts-tags" %> <html> <head> <title>登陆界面</title> </head> <body> <s:form action="login"> <table width="60%" height="76" border="0"> <!-- 各标签定义 --> <s:textfield name="username" label="用户名"/> <s:password name="password" label="密 码" /> <s:submit value="登录" align="center"/> </table> </s:form> </body> </html> LoginAction.java: package org.sunxin.struts2.ch002.action; import com.opensymphony.xwork2.Action; public class LoginAction implements Action { private String username; private String password; public void setUsername(String username){ this.username = username; } public void setPassword(String password){ this.password = password; } public String getUsername(){ return username; } public String getPassword(){ return password; } public String execute() throws Exception { username = this.getUsername(); password = this.getPassword(); System.out.println(username); System.out.println(password); if(username.equals("zhangsan")&&( password.equals("1234"))) return "ok"; else return ERROR; } } 错误信息: 2013-11-4 16:33:41 com.opensymphony.xwork2.ognl.OgnlValueStack warn 警告: Error setting expression 'user.password' with value '[Ljava.lang.String;@d6cacdd' ognl.OgnlException: target is null for setProperty(null, "password", [Ljava.lang.String;@d6cacdd) at ognl.OgnlRuntime.setProperty(OgnlRuntime.java:2326) at ognl.ASTProperty.setValueBody(ASTProperty.java:127) at ognl.SimpleNode.evaluateSetValueBody(SimpleNode.java:220) at ognl.SimpleNode.setValue(SimpleNode.java:301) at ognl.ASTChain.setValueBody(ASTChain.java:227) at ognl.SimpleNode.evaluateSetValueBody(SimpleNode.java:220) at ognl.SimpleNode.setValue(SimpleNode.java:301) at ognl.Ognl.setValue(Ognl.java:737) at com.opensymphony.xwork2.ognl.OgnlUtil.setValue(OgnlUtil.java:234) at com.opensymphony.xwork2.ognl.OgnlValueStack.trySetValue(OgnlValueStack.java:183) at com.opensymphony.xwork2.ognl.OgnlValueStack.setValue(OgnlValueStack.java:170) at com.opensymphony.xwork2.ognl.OgnlValueStack.setParameter(OgnlValueStack.java:148) at com.opensymphony.xwork2.interceptor.ParametersInterceptor.setParameters(ParametersInterceptor.java:318) at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:231) at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:239) at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:191) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) at org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:73) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:91) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:252) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) at com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:100) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) at com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:141) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) at com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:145) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) at com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:171) at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) at com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:161) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:193) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:189) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:54) at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:563) at org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:434) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1008) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) at java.lang.Thread.run(Thread.java:619) 2013-11-4 16:33:41 com.opensymphony.xwork2.ognl.OgnlValueStack warn 警告: Error setting expression 'user.username' with value '[Ljava.lang.String;@59c8e80d' ognl.OgnlException: target is null for setProperty(null, "username", [Ljava.lang.String;@59c8e80d) at ognl.OgnlRuntime.setProperty(OgnlRuntime.java:2326) at ognl.ASTProperty.setValueBody(ASTProperty.java:127) at ognl.SimpleNode.evaluateSetValueBody(SimpleNode.java:220) at ognl.SimpleNode.setValue(SimpleNode.java:301) at ognl.ASTChain.setValueBody(ASTChain.java:227) at ognl.SimpleNode.evaluateSetValueBody(SimpleNode.java:220) at ognl.SimpleNode.setValue(SimpleNode.java:301) at ognl.Ognl.setValue(Ognl.java:737) at com.opensymphony.xwork2.ognl.OgnlUtil.setValue(OgnlUtil.java:234) at com.opensymphony.xwork2.ognl.OgnlValueStack.trySetValue(OgnlValueStack.java:183) at com.opensymphony.xwork2.ognl.OgnlValueStack.setValue(OgnlValueStack.java:170) at com.opensymphony.xwork2.ognl.OgnlValueStack.setParameter(OgnlValueStack.java:148) at com.opensymphony.xwork2.interceptor.ParametersInterceptor.setParameters(ParametersInterceptor.java:318) at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:231) at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:239) at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:191) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) at org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:73) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:91) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:252) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) at com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:100) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) at com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:141) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) at com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:145) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) at com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:171) at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) at com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:161) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:193) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:189) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:54) at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:563) at org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:434) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1008) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) at java.lang.Thread.run(Thread.java:619) null null 2013-11-4 16:33:41 org.apache.struts2.dispatcher.Dispatcher error 严重: Exception occurred during processing request: null java.lang.NullPointerException at org.sunxin.struts2.ch002.action.LoginAction.execute(LoginAction.java:28) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:450) at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:289) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:252) at org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:256) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:167) at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:265) at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68) at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:138) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:239) at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:239) at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:191) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) at org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:73) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:91) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:252) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) at com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:100) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) at com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:141) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) at com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:145) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) at com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:171) at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) at com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:161) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:193) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:189) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:54) at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:563) at org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:434) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1008) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) at java.lang.Thread.run(Thread.java:619)
使用Struts2配置国际化的问题,请大家帮忙.谢谢.
我在使用Struts2配置国际化的问题时, 在jsp页面使用 <h2><s:text name="wmbmm.login.username"/></h2> 引用国际化文件的key. 然后再src的目录下,配置了struts.properties属性文件中配置了. struts.custom.i18n.resources=globalMessages 在项目的src目录下, 配置了 globalMessages_en_US.properties wmbmm.login.username=UserName wmbmm.login.password=PassWord globalMessages_zh_CN.properties wmbmm.login.username=\u7528\u6237\u540D wmbmm.login.password=\u5BC6\u7801 重启服务器,打开浏览器访问的时候,就报下面这个错误!请问还需要配置什么吗? 严重: Servlet.service() for servlet jsp threw exception The Struts dispatcher cannot be found. This is usually caused by using Struts tags without the associated filter. Struts tags are only usable when the request has passed through its servlet filter, which initializes the Struts dispatcher needed for this tag. - [unknown location] at org.apache.struts2.views.jsp.TagUtils.getStack(TagUtils.java:60) at org.apache.struts2.views.jsp.StrutsBodyTagSupport.getStack(StrutsBodyTagSupport.java:44) at org.apache.struts2.views.jsp.ComponentTagSupport.doStartTag(ComponentTagSupport.java:48) at org.apache.jsp.login_jsp._jspx_meth_s_005ftext_005f0(login_jsp.java:267) at org.apache.jsp.login_jsp._jspService(login_jsp.java:197) at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) at javax.servlet.http.HttpServlet.service(HttpServlet.java:803) at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393) at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320) at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266) at javax.servlet.http.HttpServlet.service(HttpServlet.java:803) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) 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(Thread.java:619)
struts2 result的jsp页面如何规定width和height?
struts2 result的jsp页面如何规定width和height? 比如我的struts.xml中定义了下面这段 [code="java"] action name="xxx" class="xxxAction"> <result name="input">/index.jsp</result> <result name="error">/error.jsp</result> <result name="success">/message.jsp</result> </action> [/code] 当xxxAction return success后,IE浏览器弹出了message.jsp页面 我如何设定弹出的IE页面的属性,像toolbar=no这样的设置? 我知道js中的window.open()第三个参数就能实现弹出窗口的属性设置,比如toolbar=no。 但是在struts2架构下该在哪里写下toolbar=no这行代码? 我们再来看一下struts2的"运行轨迹" index.html中定义 <s:form action="login" target="_blank"> <s:submit value="登录" /> </s:form> 当我点击登录后执行loginAction.java中的excute() 然后excute()返回了"success" 考虑到我在struts.xml中配置了 <action name="login" class="loginAction"> <result name="success">/message.jsp</result> </action> 所以浏览器弹出了一个新的窗口 我想解决的就是如何让这个新弹出的窗口上没有菜单栏和地址栏
struts2整合sitemesh无法访问action问题
struts2版本2.3.24 sitemesh2.4.2 应有的jar包都已加入 web.xml ``` <filter> <filter-name>sitemesh</filter-name> <filter-class>com.opensymphony.sitemesh.webapp.SiteMeshFilter</filter-class> </filter> <filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> </filter> <filter-mapping> <filter-name>sitemesh</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> ``` decorators.xml ``` <decorators defaultdir="/WEB-INF/decorators/"> <excludes> <pattern>/login.jsp</pattern> <pattern>/common/**</pattern> </excludes> <decorator name="main" page="default.jsp"> <pattern>/*</pattern> </decorator> </decorators> ``` 这时候直接访问http://localhost:8080/login.jsp是正确的,没有被装饰, 访问http://localhost:8080/test/test.jsp是被装饰了的。 但是通过action跳转http://localhost:8080/login.action---result返回test/test.jsp 直接报空指针异常(ps:action里面没有任何业务代码,就是一个return success),异常信息: ``` java.lang.NullPointerException at org.apache.struts2.components.ServletUrlRenderer.renderUrl(ServletUrlRenderer.java:80) at org.apache.struts2.components.URL.end(URL.java:147) at org.apache.struts2.views.jsp.ComponentTagSupport.doEndTag(ComponentTagSupport.java:42) at org.apache.jsp.WEB_002dINF.decorators.default_jsp._jspx_meth_s_005furl_005f0(default_jsp.java:307) at org.apache.jsp.WEB_002dINF.decorators.default_jsp._jspService(default_jsp.java:100) at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) at javax.servlet.http.HttpServlet.service(HttpServlet.java:727) at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432) at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395) at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339) at javax.servlet.http.HttpServlet.service(HttpServlet.java:727) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:748) at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:604) at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:543) at com.opensymphony.sitemesh.compatability.OldDecorator2NewDecorator.render(OldDecorator2NewDecorator.java:46) at com.opensymphony.sitemesh.webapp.decorator.BaseWebAppDecorator.render(BaseWebAppDecorator.java:33) at com.opensymphony.sitemesh.webapp.SiteMeshFilter.doFilter(SiteMeshFilter.java:84) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:85) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:503) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:421) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1070) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:314) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:745) ``` 根据异常信息看是是被sitemesh的filter过滤了,struts2的action都没进入,不知怎么回事,网上说加入ActionContextCleanUp,但是这个类已经过时了
struts2中<result>/MyJsp.jsp</result>不跳转
SSH做个登录案例,<form action="userlogin">请求到struts2中的action方法中 页面始终无法跳转jsp页面 代码如下 UserAction.java代码如下 @Controller public class UserAction { /** * 用户登录 */ public String login() { System.out.println("用户登录"); return "success"; } } struts.xml配置如下 <package name="" extends="struts-default" namespace="/"> <action name="user*" class="userAction" method="{1}"> <result name="success">MyJsp.jsp</result> </action> </package> login.jsp代码如下 <form action="userlogin" id="loginForm" method="post"> //此处省略登录代码 </form>
struts2 装入包含检查是否登录的拦截器锥后,.jsp_Service()出现异常
我设置检查用户是否登录的包后,所有需要加载数据的页面出现是空白页面 2014-6-8 1:07:53 org.apache.catalina.core.StandardWrapperValve invoke 严重: Servlet.service() for servlet jsp threw exception java.lang.NullPointerException at org.apache.jsp.user.deleteuser_jsp._jspService(deleteuser_jsp.java:185) at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) at javax.servlet.http.HttpServlet.service(HttpServlet.java:803) at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393) at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320) at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266) at javax.servlet.http.HttpServlet.service(HttpServlet.java:803) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at crm.filter.EncodingFilter.doFilter(EncodingFilter.java:17) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:88) 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(Thread.java:619) struts.xml <?xml version="1.0" encoding="GBK"?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN" "http://struts.apache.org/dtds/struts-2.3.dtd"> <struts> <!--指定Spring框架的自动装配模式 --> <constant name="struts.objectFactory.spring.autoWrite " value="name"></constant> <constant name="struts.i18.encoding" value="GBK"></constant> <package name="common" namespace="/" extends="struts-default"> <action name="login" class="crm.web.struts.action.LoginAction"> <result name="success">/index.jsp</result> <result name="fail">/error.jsp</result> <result name="input">/user/login.jsp</result> </action> </package> <package name="struts" namespace="/" extends="struts-default"> <!-- 设置该包的默认拦截器 --> <interceptors> <interceptor name="loginInterceptor" class="crm.web.interceptor.LoginInterceptor"/> <interceptor name="authorityInterceptor" class="crm.web.interceptor.AuthorityInterceptor"/> <interceptor-stack name="myDefaultInterceptorStack"> <interceptor-ref name="loginInterceptor"/> <interceptor-ref name="defaultStack"/> </interceptor-stack> </interceptors> <default-interceptor-ref name="myDefaultInterceptorStack"/> <global-results> <result name="login" type="redirect">/user/login.jsp</result> </global-results> <action name="cancellation" class="crm.web.struts.action.CancellationAction"> <result name="success" type="redirect">/user/login.jsp</result> <result name="error" type="redirect">/error.jsp</result> </action> <action name="charge" class="crm.web.struts.action.ChargeAction"> <result name="success">/index.jsp</result> <result name="input" type="redirect">/pay/charge.jsp</result> <result name="error">/error.jsp</result> </action> <action name="payAction" class="crm.web.struts.action.PayAction"> <result name="success">/index.jsp</result> <result name="input" type="redirect">/pay/pay.jsp</result> <result name="error">/error.jsp</result> </action> deleteuserjsp页面 </head> <body > <s:action name="loadMemberList!pageOfDelete" namespace="/" ></s:action> <%ArrayList list=(ArrayList)request.getAttribute("list"); Iterator it=list.iterator(); int i=0; Member m[]=new Member[5]; while(it.hasNext()){ m[i++]=(Member)it.next(); if(i==5){break;} } %> <s:url id="toLastPage" action="memberList!pageOfDelete" namespace="/" > <s:param name="pageType" value="-1"></s:param> </s:url> <s:url id="toNextPage" action="memberList!pageOfDelete" namespace="/" > <s:param name="pageType" value="1"></s:param> </s:url> <div class="twelve columns header_nav"> <div class="leftdiv" style="color:#FF4500;font-size:15px"><span>尊敬的<%=((User)session.getAttribute("currentUser")).getUserName()%>你好,</span><a href="<%=path%>/cancellation">退出</a></div> <div class="row"> <ul id="menu-header" class="nav-bar horizontal"> <li class="active"><a href="../index.jsp">Home</a></li> <li class="has-flyout"> <a href="#">会员信息管理</a><a href="#" class="flyout-toggle"></a> <ul class="flyout"><!-- Flyout Menu --> <li class="has-flyout"><a href="./adduser.jsp">会员信息增加</a></li> <li class="has-flyout"><a href="./deleteuser.jsp">会员信息删除</a></li> <li class="has-flyout"><a href="./alteruser.jsp">会员信息修改</a></li> </ul> </li><!-- END Flyout Menu --> <li class="has-flyout"> <a href="#">消息推送</a><a href="#" class="flyout-toggle"></a> <ul class="flyout"><!-- Flyout Menu --> <li class="has-flyout"><a href="../send/addsend.jsp">创建推送</a></li> <li class="has-flyout"><a href="../send/deletesend.jsp">删除推送</a></li> </ul> </li> <li class="has-flyout"> <a href="#">权限管理</a><a href="#" class="flyout-toggle"></a> <ul class="flyout"><!-- Flyout Menu --> <li class="has-flyout"><a href="../worker/addworker.jsp">增加收用户</a></li> <li class="has-flyout"><a href="../worker/deleteworker.jsp">删除用户</a></li> </ul> </li> <li class="has-flyout"> <a href="#">充值缴费</a><a href="#" class="flyout-toggle"></a> <ul class="flyout"><!-- Flyout Menu --> <li class="has-flyout"><a href="../pay/charge.jsp">充值</a></li> <li class="has-flyout"><a href="../pay/pay.jsp">缴费</a></li> </ul> </li> </ul> <script type="text/javascript"> //<![CDATA[ $('ul#menu-header').nav-bar(); //]]> </script> </div> </div> <section class="section_light"> <div class="row"><form method="post" action=""> <table class="table table-striped" > <thead> <tr> <th> 编号 </th> <th> 会员名 </th> <th> 卡号 </th> <th> 余额 </th> </tr> </thead> <tbody> <tbody> <tr> <td> 1 </td> <td> <%if(m[0]!=null){out.print(m[0].getName());}%> </td> <td> <%if(m[0]!=null){out.print(m[0].getId());}%> </td> <td> <%if(m[0]!=null){out.print(m[0].getOverage());}%> </td> </tr> <tr class="success"> <td> 2 </td> <td> <%if(m[1]!=null){out.print(m[1].getName());}%> </td> <td> <%if(m[1]!=null){out.print(m[1].getId());}%> </td> <td> <%if(m[1]!=null){out.print(m[1].getOverage());}%> </td> </tr> <tr class="error"> <td> 3 </td> <td> <%if(m[2]!=null){out.print(m[2].getName());}%> </td> <td> <%if(m[2]!=null){out.print(m[2].getId());}%> </td> <td> <%if(m[2]!=null){out.print(m[2].getOverage());}%> </td> </tr> <tr class="warning"> <td> 4 </td> <td> <%if(m[3]!=null){out.print(m[3].getName());}%> </td> <td> <%if(m[3]!=null){out.print(m[3].getId());}%> </td> <td> <%if(m[3]!=null){out.print(m[3].getOverage());}%> </td> </tr> <tr class="info"> <td> 5 </td> <td> <%if(m[4]!=null){out.print(m[4].getName());}%> </td> <td> <%if(m[4]!=null){out.print(m[4].getId());}%> </td> <td> <%if(m[4]!=null){out.print(m[4].getOverage());}%> </td> </tr> </tbody> </table></form> </div><div class="row"> <div style="float:left ;position:relative; left:30%;"><a href="<%=path%>/memberList!pageOfDelete?page_Type=-1"><img src="../images/last.jpg" width="81" height="26" /></a></div> <div style="float:left ; position:relative; left:50%;"><a href="<%=path%>/memberList!pageOfDelete?page_Type=1"><img src="../images/next.jpg" width="81" height="26" /></a></div> </div></br></br></br><div class="row"> <table ><form method="post" action="<%=path%>/deleteMember"> <tr> <td ><span>会员名</span> </td> <td ><div> <input name="name" type="text" id="huiyuanming" style="height:28px;width:267px;outline:none; vertical-align:middle;" /> </div></td> <td ><span>卡号</span> </td> <td ><div> <input name="id" type="text" id="kahao" style="height:28px;width:267px;outline:none; vertical-align:middle;" /> </div> </td> <td> <td colspan="2"><div align="center"><input name="deleteuse" type="submit" value="" style="border:none;background:url('../images/delete.jpg') left top no-repeat;width:81px; height:26px;" /></div></td> </td></tr></form> </table> </div></div> </section>
使用struts2框架表单无法提交到第二个页面
struts.xml中 <struts> <package name="struts2" extends="struts-default"> <action name="login" class="com.test.action.LoginAction"> <result>/Result.jsp</result> </action> </package> </struts> web.xml中 <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> Login.jsp中 <form action="login.action" method="post"> username:<input type="text" name="username"/><br/> password:<input type="text" name="password"/><br/> <input type="submit" value="submit"/> </form> Result.jsp中 <body> username:${requestScope.username }<br/> password:${requestScope.password } </body> 为什么表单提交之后就是404错误 无法跳转到Result.jsp页面呢???
struts 2 com.opensymphony.xwork2.u报错
六月 29, 2016 8:47:55 上午 com.opensymphony.xwork2.util.logging.jdk.JdkLogger error 严重: Exception occurred during processing request: null java.lang.NullPointerException 提示在这一个代码段里面 if语句错误 package cn.itcast.actionT; import cn.itcast.domain.User; import com.opensymphony.xwork2.ActionContext; import com.opensymphony.xwork2.ActionSupport; import com.opensymphony.xwork2.ModelDriven; public class LoginAction extends ActionSupport implements ModelDriven<User>{ private static final long serializableUID = 1L; private User user; @Override public User getModel() { return user; } @Override public String execute()throws Exception{ //获取ActionContext ActionContext context = ActionContext.getContext(); if("tom".equals(user.getUsername())&&"123".equals(user.getPassword())){ context.getSession().put("user","user"); return SUCCESS; }else { context.getSession().put("msg", "登录失败"); return INPUT; } } } 我把所有代码都复制上来 package cn.itcast.actionT; import cn.itcast.domain.User; import com.opensymphony.xwork2.ActionSupport; public class BookAction extends ActionSupport{ private User user; public String add(){ System.out.println("book add"); return SUCCESS; } public String del(){ System.out.println("book del"); return SUCCESS; } public String update(){ System.out.println("book update"); return SUCCESS; } public String find(){ System.out.println("book find"); return SUCCESS; } } package cn.itcast.domain; public class User { private String username; private String password; 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; } } struts.xml package name="default" namespace="/" extends="struts-default"> interceptors> interceptor name="privilege" class="cn.itcast.interceptor.PrivilegeInterceptor"/> /interceptors> action name="login" class="cn.itcast.actionT.LoginAction"> result>/main.jsp /result> result name="input">/login.jsp /result> /action> action name="book_*" class="cn.itcast.actionT.BookAction" method="{1}"> result>/success.jsp /result> result name="login">/login.jsp /result> interceptor-ref name="privilege"/> /action> /package> /struts> main.jsp a href="/Two/book_del">book_del /a> a href="/Two/book_add">book_add /a> a href="/Two/book_find">book_find /a> a href="/Two/book_update">book_update /a> login.jsp form action="/Two/login.action" method="post"> 用户名:input type="text" name="username"/>br> 密码:input type="password" name="password"/>br> input type="submit" value="登录™†"/> /form>
struts2中JSP转发CSS不显示的问题
[color=red]如果这样写CSS正常:[/color] a.jsp页面 <a href="user.jsp">用户页面<a> [color=darkred]如果在配置文件中转发JSP,CSS就不显示:[/color] a.jsp页面 <a href="login/autocompletertag.action">用户页面<a> struts.xml: <package name="login" extends="struts-default"> <action name="autocompletertag" class="cn.eastgf.gafis.action.AutocompleterAction"> <result name="auto">/user.jsp</result> </action> </package >
struts2执行行未找到execute方法
struts.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> <package name="test" extends="struts-default"> <action name="login" class="com.zy.action.Login" > <result name="login-success">/WEB-INF/login-success.jsp</result> </action> </package> </struts> ``` Login.java ``` import java.util.Map; import org.apache.struts2.interceptor.ApplicationAware; import org.apache.struts2.interceptor.SessionAware; import com.opensymphony.xwork2.ActionSupport; public class Login extends ActionSupport implements SessionAware, ApplicationAware { private String username; private Map<String, Object> session; private Map<String, Object> application; public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public void setSession(Map<String, Object> arg0) { // TODO Auto-generated method stub this.session = arg0; } public void setApplication(Map<String, Object> arg1) { // TODO Auto-generated method stub this.application = arg1; } @Override public String execute() throws Exception { // TODO Auto-generated method stub session.put("username", username); Integer count = (Integer) application.get("count"); if (count == null) { count = 0; } count++; application.put("count", count); return "login-success"; } } ``` java.lang.NoSuchMethodException: com.zy.action.Login.execute() java.lang.Class.getMethod(Class.java:1605) org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.getActionMethod(AnnotationValidationInterceptor.java:75) org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:47) com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:138) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:239) com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:239) com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:191) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:73) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:91) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:252) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:100) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:141) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:145) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:171) com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:161) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:193) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:189) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:54) org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:563) org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77) org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:99) note The full stack trace of the root cause is available in the Apache Tomcat/7.0.62 logs.
struts2表单验证 jsp页面显示不了错误信息
目前正在用struts2创建项目 为了减小代码的耦合度 使bean类更纯粹点 在表单验证这一块 我另外写了一个类 然后用模型驱动(ModelDriven) 再重写validate方法 [code="java"] package com.pp.action.login; import com.opensymphony.xwork2.ActionSupport; import com.opensymphony.xwork2.ModelDriven; import com.pp.bean.Login; public class myvalidation extends ActionSupport implements ModelDriven<Login> { private Login login = new Login(); private String mailname; private String username; private String password; public Login getModel() { return login; } @Override public void validate() { // System.out.println("validate"); // mailname = login.getMailname().trim(); // username = login.getUsername().trim(); // password = login.getPassword().trim(); // System.out.println("mail"+mailname); // System.out.println("username---"+username); // System.out.println("password---"+password); if(login.getMailname().equals("")) { this.addFieldError("mailname","mail name should not be blank!"); System.out.println("mail validate"); //this.addActionError("mailname should not be blank!"); } if(login.getMailname().length()<1) { this.addFieldError("mailname","length error"); System.out.println("mail length validate"); //this.addActionError("length error"); } if(login.getUsername().equals("") || login.getUsername().length()<6 || login.getUsername().length()>12) { this.addFieldError("username","username should not be blank!"); System.out.println("username validate"); //this.addActionError("username should bot be blank"); } if(login.getPassword().equals("")) { this.addFieldError("password","fill your password"); System.out.println("password validate"); //this.addActionError("fill your password"); } } @Override public String execute() throws Exception { return SUCCESS; } } [/code] 后台都有显示mail validate username validate等输出信息 说明有进入判断条件 但是在JSP页面就是显示不出来错误信息 reg.jsp页面在form表单之前也有加FieldError的标签: [code="java"] <body> <s:fielderror></s:fielderror> <s:form action="login2"> <!-- <s:label name="label" value="输入你的常用邮箱,用于登录"></s:label> <s:label name="label" value="用户名只能由字母、下划线、数字组成"></s:label> <s:label name="label" value="密码6——12位组成"></s:label> --> <s:textfield name="mailname" label="邮箱"></s:textfield> <s:textfield name="username" label="用户名"></s:textfield> <s:textfield name="password" label="密码"/> <s:submit name="submit" ></s:submit> </s:form> <br> </body> [/code] acton如下,用的是login2来处理表单: [code="java"] <include file="struts-default.xml" /> <package name="tutorial" extends="struts-default"> <action name="login" class="com.pp.action.login.checklogin"> <result name="success">success.jsp</result> <result name="error">error.jsp</result> <result name="login">login.jsp</result> </action> <action name="login2" class="com.pp.action.login.myvalidation"> <result>success.jsp</result> <result name="input">reg.jsp</result> </action> </package> <!-- <action name="login2" class="com.pp.action.login.myvalidation"> <action name="login2" class="com.pp.bean.Login"> --> </struts> [/code] 到底是什么问题 希望各位帮忙看下 非常感谢。。。 [b]问题补充:[/b] Login类是另外写的 然后为用模型驱动ModelDriven<Login> 其中有个getModel()方法重载Login的javaBean类 首先我想说 struts2的表单验证是不是有两种:一是直接override validate方法;二是直接对Action处理类配置xml文件 不是吗 [b]问题补充:[/b] wocsok (中级程序员)说得不对 既然是使用ModelDriven,它的作用就像是在Myvalidation里面写了Login类的getXX和setXX方法作用是一样的。 我的问题是在原先的Login里面的validate()方法没注释掉,然后两个validate()方法冲突了,只要把Login里面的validate注释掉就OK了
struts报Unable to load configuration. - action
1. web.xml文件内容: ``` <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"> <filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> </web-app> ``` 2. struts.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> <package name="default" namespace="/" extends="struts-default"> <action name="Login" class="lee.Login"> <result name="error">/error.jsp</result> </action> </package> </struts> ``` 3. action类的内容 ``` package lee; public class Login { private String username; private String password; 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; } // 处理用户请求的execute方法 public String execute() throws Exception { // 当用户请求参数的username等于scott,密码请求参数为tiger时,返回success字符串 // 否则返回error字符串 if (getUsername().equals("scott") && getPassword().equals("tiger")) { return "success"; } else { return "error"; } } } ``` 错误信息: 11:26:40.635 [localhost-startStop-1] ERROR org.apache.struts2.dispatcher.Dispatcher - Dispatcher initialization failed com.opensymphony.xwork2.config.ConfigurationException: Unable to load configuration. at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:70) ~[xwork-core-2.3.24.jar:2.3.24] at org.apache.struts2.dispatcher.Dispatcher.getContainer(Dispatcher.java:967) ~[struts2-core-2.3.24.jar:2.3.24] at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:435) ~[struts2-core-2.3.24.jar:2.3.24] at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:479) [struts2-core-2.3.24.jar:2.3.24] at org.apache.struts2.dispatcher.ng.InitOperations.initDispatcher(InitOperations.java:74) [struts2-core-2.3.24.jar:2.3.24] at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.init(StrutsPrepareAndExecuteFilter.java:57) [struts2-core-2.3.24.jar:2.3.24] at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:279) [catalina.jar:7.0.63] at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:260) [catalina.jar:7.0.63] at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:105) [catalina.jar:7.0.63] at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4855) [catalina.jar:7.0.63] at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5549) [catalina.jar:7.0.63] at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) [catalina.jar:7.0.63] at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1574) [catalina.jar:7.0.63] at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1564) [catalina.jar:7.0.63] at java.util.concurrent.FutureTask.run(FutureTask.java:262) [?:1.7.0_80] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [?:1.7.0_80] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [?:1.7.0_80] at java.lang.Thread.run(Thread.java:745) [?:1.7.0_80] Caused by: com.opensymphony.xwork2.config.ConfigurationException: Action class [lee.Login] not found at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.verifyAction(XmlConfigurationProvider.java:486) ~[xwork-core-2.3.24.jar:2.3.24] at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.addAction(XmlConfigurationProvider.java:429) ~[xwork-core-2.3.24.jar:2.3.24] at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.addPackage(XmlConfigurationProvider.java:556) ~[xwork-core-2.3.24.jar:2.3.24] at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.loadPackages(XmlConfigurationProvider.java:295) ~[xwork-core-2.3.24.jar:2.3.24] at org.apache.struts2.config.StrutsXmlConfigurationProvider.loadPackages(StrutsXmlConfigurationProvider.java:112) ~[struts2-core-2.3.24.jar:2.3.24] at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:264) ~[xwork-core-2.3.24.jar:2.3.24] at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:67) ~[xwork-core-2.3.24.jar:2.3.24] ... 17 more 八月 03, 2015 11:26:40 上午 org.apache.catalina.core.StandardContext filterStart 严重: Exception starting filter struts2 Unable to load configuration. - action - file:/D:/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp1/wtpwebapps/struts_001/WEB-INF/classes/struts.xml:8:42 at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:493) at org.apache.struts2.dispatcher.ng.InitOperations.initDispatcher(InitOperations.java:74) at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.init(StrutsPrepareAndExecuteFilter.java:57) at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:279) at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:260) at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:105) at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4855) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5549) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1574) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1564) at java.util.concurrent.FutureTask.run(FutureTask.java:262) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:745) Caused by: Unable to load configuration. - action - file:/D:/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp1/wtpwebapps/struts_001/WEB-INF/classes/struts.xml:8:42 at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:70) at org.apache.struts2.dispatcher.Dispatcher.getContainer(Dispatcher.java:967) at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:435) at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:479) ... 14 more Caused by: Action class [lee.Login] not found - action - file:/D:/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp1/wtpwebapps/struts_001/WEB-INF/classes/struts.xml:8:42 at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.verifyAction(XmlConfigurationProvider.java:486) at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.addAction(XmlConfigurationProvider.java:429) at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.addPackage(XmlConfigurationProvider.java:556) at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.loadPackages(XmlConfigurationProvider.java:295) at org.apache.struts2.config.StrutsXmlConfigurationProvider.loadPackages(StrutsXmlConfigurationProvider.java:112) at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:264) at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:67) ... 17 more 八月 03, 2015 11:26:40 上午 org.apache.catalina.core.StandardContext startInternal 严重: One or more Filters failed to start. Full details will be found in the appropriate container log file 八月 03, 2015 11:26:40 上午 org.apache.catalina.core.StandardContext startInternal 严重: Context [/struts_001] startup failed due to previous errors 八月 03, 2015 11:26:40 上午 org.apache.coyote.AbstractProtocol start 信息: Starting ProtocolHandler ["http-apr-8080"] 八月 03, 2015 11:26:40 上午 org.apache.coyote.AbstractProtocol start 信息: Starting ProtocolHandler ["ajp-apr-8009"] 八月 03, 2015 11:26:40 上午 org.apache.catalina.startup.Catalina start 信息: Server startup in 2523 ms 只要去掉struts.xml文件中的class="lee.Login"就不报错了 struts的jar文件 ![图片说明](https://img-ask.csdn.net/upload/201508/03/1438572924_999031.png)
struts2.1整合spring2.5后使用fileUpload的文件上传
struts2.1单独使用fileUpload没有问题,可以正常使用。 但是整合了spring2.5.6之后,就出现了一个让我匪夷所思的问题。 问题是这样:整合后,再上传文件,如果符合fileUpload的要求,那么上传没问题。 但是,如果文件上传的类型或者文件的大小不符合要求,那么本次上传失败。这也没问题。 问题是,在失败之后,我刷新页面,上传一个符合要求的文件,还是显示上传失败的信息。 而且文件的确上传失败了,后台也不走action了,感觉被fileUpload直接拦截了, 并且拦截器,获得的还是以前那个失败的信息。这个我就晕了。 有谁知道这个问题产生的原因是什么吗?请告知!谢谢! 以下是我使用的代码: 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> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> </web-app> 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:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"> <bean id="upload" class="cn.sure.action.UploadAction"> </bean> </beans> struts.xml <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <package name="struts2" extends="struts-default"> <action name="upload" class="upload"> <result name="input">/upload.jsp</result> <result name="success">/index.jsp</result> <param name="savePath">/upload</param> <interceptor-ref name="fileUpload"> <param name="maximumSize">204800</param> </interceptor-ref> <interceptor-ref name="defaultStack"></interceptor-ref> </action> </package> </struts> UploadAction.java package cn.sure.action; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.InputStream; import org.apache.struts2.ServletActionContext; import com.opensymphony.xwork2.ActionSupport; public class UploadAction extends ActionSupport { private static final long serialVersionUID = 2865729575435431264L; private File fj ; private String savePath ; private String fjContentType ; private String fjFileName ; private String test ; @Override public String execute() throws Exception { String path = ServletActionContext.getServletContext().getRealPath(savePath) ; InputStream in = new FileInputStream(fj) ; FileOutputStream out = new FileOutputStream(new File(path, fjFileName)) ; byte[] b = new byte[1024] ; int len = 0 ; while((len = in.read(b)) > 0){ out.write(b, 0, len) ; } in.close() ; out.close() ; return SUCCESS; } public File getFj() { return fj; } public String getFjContentType() { return fjContentType; } public String getFjFileName() { return fjFileName; } public String getTest() { return test; } public void setFj(File fj) { this.fj = fj; } public void setFjContentType(String fjContentType) { this.fjContentType = fjContentType; } public void setFjFileName(String fjFileName) { this.fjFileName = fjFileName; } public void setTest(String test) { this.test = test; } public String getSavePath() { return savePath; } public void setSavePath(String savePath) { this.savePath = savePath; } } upload.jsp <form action="upload.action" method="post" enctype="multipart/form-data"> <input type="text" name="test" /><br/> <input type="file" name="fj" /><br/> <input type="submit" value="SUBMIT" /> </form> [b]问题补充:[/b] 按照你说的我将 <bean id="upload" class="cn.sure.action.UploadAction"> </bean> 改为 <bean id="upload" class="cn.sure.action.UploadAction" scope="propotype"> </bean> 结果。。。。。。,抛了个异常 Unable to instantiate Action, login, defined for 'login' in namespace '/'No Scope registered for scope 'propotype' com.opensymphony.xwork2.DefaultActionInvocation.createAction(DefaultActionInvocation.java:307) com.opensymphony.xwork2.DefaultActionInvocation.init(DefaultActionInvocation.java:388) com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:187) org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:61) org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:39) com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:47) org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:478) org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77) org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91) java.lang.IllegalStateException: No Scope registered for scope 'propotype' org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:295) org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185) org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164) org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:880) com.opensymphony.xwork2.spring.SpringObjectFactory.buildBean(SpringObjectFactory.java:130) com.opensymphony.xwork2.ObjectFactory.buildBean(ObjectFactory.java:139) com.opensymphony.xwork2.ObjectFactory.buildAction(ObjectFactory.java:109) com.opensymphony.xwork2.DefaultActionInvocation.createAction(DefaultActionInvocation.java:288) com.opensymphony.xwork2.DefaultActionInvocation.init(DefaultActionInvocation.java:388) com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:187) org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:61) org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:39) com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:47) org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:478) org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77) org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91) 晕死,难道是不能这样用,还是我哪里用错了呢,唉, 原来以为我已经会整合ssh2了,结果今天才发现自己的无知!!! [b]问题补充:[/b] <bean id="upload" class="cn.sure.action.UploadAction" scope="propotype"> </bean> 太阳啊,搞了一天了,终于知道问题出在哪里了 我太阳。。。。。。。。。。。。。。。。。。。。 单词写错了,太TM丢人了。。。。。。。。 prototype --- 我写的是 propotype :twisted: 另外我的springbean没有 singleton 只有scope,估计是版本的问题吧。 我用的是spring2.5.6
struts2 Convention-plugin 的使用问题
[code="java"] <constant name="struts.convention.result.path" value="/WEB-INF/admin" /> <constant name="struts.convention.package.locators" value="web,action" /> <constant name="struts.convention.classes.reload" value="true" /> <constant name="struts.convention.action.name.separator" value="-" /> <constant name="struts.convention.action.suffix" value="Action"/> [/code] [code="java"] @Namespace("/center") public class LoginAction extends ActionSupport{ public String login(){ return INDEX; } } [/code] 工程目录jsp位置 webapp/web-inf/admin/center/login-index.jsp jar包已添加 页面通过/center/login!login.action 无法访问,不知哪里出错,请大神给予解答。。。。
刚学ssh框架做了一个项目 jsp页面无法获取action的值,求教啊。。。以下是代码
页面都正常跳转 就是取不到值 用的是iframe框架 main.jsp可以获取,不过main.jsp指向的top.jsp页面无法获取值 Action部分代码 private static final long serialVersionUID = 1L; private UserService userService; private User user; public String login(){ List<User> list=new ArrayList<User>(); list=userService.login(user); if(list.size()>0){ return SUCCESS; }else{ return ERROR; } } public User getUser() { return user; } public void setUser(User user) { this.user = user; } jsp页面获取值部分(top.jsp) <td width="59%" valign="bottom"><div align="center" class="STYLE1">当前用户:${user.username}</div></td> struts配置文件 <struts> <package name="ngbaojia" namespace="/" extends="struts-default"> <action name="login" class="UserAction" method="login"> <result name="success">main.jsp</result> <result name="error">login.jsp</result> </action> </package> </struts>
终于明白阿里百度这样的大公司,为什么面试经常拿ThreadLocal考验求职者了
点击上面↑「爱开发」关注我们每晚10点,捕获技术思考和创业资源洞察什么是ThreadLocalThreadLocal是一个本地线程副本变量工具类,各个线程都拥有一份线程私...
《奇巧淫技》系列-python!!每天早上八点自动发送天气预报邮件到QQ邮箱
将代码部署服务器,每日早上定时获取到天气数据,并发送到邮箱。 也可以说是一个小人工智障。 思路可以运用在不同地方,主要介绍的是思路。
加快推动区块链技术和产业创新发展,2019可信区块链峰会在京召开
11月8日,由中国信息通信研究院、中国通信标准化协会、中国互联网协会、可信区块链推进计划联合主办,科技行者协办的2019可信区块链峰会将在北京悠唐皇冠假日酒店开幕。   区块链技术被认为是继蒸汽机、电力、互联网之后,下一代颠覆性的核心技术。如果说蒸汽机释放了人类的生产力,电力解决了人类基本的生活需求,互联网彻底改变了信息传递的方式,区块链作为构造信任的技术有重要的价值。   1...
阿里面试官问我:如何设计秒杀系统?我的回答让他比起大拇指
你知道的越多,你不知道的越多 点赞再看,养成习惯 GitHub上已经开源 https://github.com/JavaFamily 有一线大厂面试点脑图和个人联系方式,欢迎Star和指教 前言 Redis在互联网技术存储方面使用如此广泛,几乎所有的后端技术面试官都要在Redis的使用和原理方面对小伙伴们进行360°的刁难。 作为一个在互联网公司面一次拿一次Offer的面霸,打败了...
C语言魔塔游戏
很早就很想写这个,今天终于写完了。 游戏截图: 编译环境: VS2017 游戏需要一些图片,如果有想要的或者对游戏有什么看法的可以加我的QQ 2985486630 讨论,如果暂时没有回应,可以在博客下方留言,到时候我会看到。 下面我来介绍一下游戏的主要功能和实现方式 首先是玩家的定义,使用结构体,这个名字是可以自己改变的 struct gamerole { char n...
面试官问我:什么是消息队列?什么场景需要他?用了会出现什么问题?
你知道的越多,你不知道的越多 点赞再看,养成习惯 GitHub上已经开源 https://github.com/JavaFamily 有一线大厂面试点脑图、个人联系方式和人才交流群,欢迎Star和完善 前言 消息队列在互联网技术存储方面使用如此广泛,几乎所有的后端技术面试官都要在消息队列的使用和原理方面对小伙伴们进行360°的刁难。 作为一个在互联网公司面一次拿一次Offer的面霸...
Android性能优化(4):UI渲染机制以及优化
文章目录1. 渲染机制分析1.1 渲染机制1.2 卡顿现象1.3 内存抖动2. 渲染优化方式2.1 过度绘制优化2.1.1 Show GPU overdraw2.1.2 Profile GPU Rendering2.2 卡顿优化2.2.1 SysTrace2.2.2 TraceView 在从Android 6.0源码的角度剖析View的绘制原理一文中,我们了解到View的绘制流程有三个步骤,即m...
微服务中的Kafka与Micronaut
今天,我们将通过Apache Kafka主题构建一些彼此异步通信的微服务。我们使用Micronaut框架,它为与Kafka集成提供专门的库。让我们简要介绍一下示例系统的体系结构。我们有四个微型服务:订单服务,行程服务,司机服务和乘客服务。这些应用程序的实现非常简单。它们都有内存存储,并连接到同一个Kafka实例。 我们系统的主要目标是为客户安排行程。订单服务应用程序还充当网关。它接收来自客户的请求...
致 Python 初学者们!
作者| 许向武 责编 | 屠敏 出品 | CSDN 博客 前言 在 Python 进阶的过程中,相信很多同学应该大致上学习了很多 Python 的基础知识,也正在努力成长。在此期间,一定遇到了很多的困惑,对未来的学习方向感到迷茫。我非常理解你们所面临的处境。我从2007年开始接触 Python 这门编程语言,从2009年开始单一使用 Python 应对所有的开发工作,直至今...
究竟你适不适合买Mac?
我清晰的记得,刚买的macbook pro回到家,开机后第一件事情,就是上了淘宝网,花了500元钱,找了一个上门维修电脑的师傅,上门给我装了一个windows系统。。。。。。 表砍我。。。 当时买mac的初衷,只是想要个固态硬盘的笔记本,用来运行一些复杂的扑克软件。而看了当时所有的SSD笔记本后,最终决定,还是买个好(xiong)看(da)的。 已经有好几个朋友问我mba怎么样了,所以今天尽量客观...
程序员一般通过什么途径接私活?
二哥,你好,我想知道一般程序猿都如何接私活,我也想接,能告诉我一些方法吗? 上面是一个读者“烦不烦”问我的一个问题。其实不止是“烦不烦”,还有很多读者问过我类似这样的问题。 我接的私活不算多,挣到的钱也没有多少,加起来不到 20W。说实话,这个数目说出来我是有点心虚的,毕竟太少了,大家轻喷。但我想,恰好配得上“一般程序员”这个称号啊。毕竟苍蝇再小也是肉,我也算是有经验的人了。 唾弃接私活、做外...
字节跳动面试官这样问消息队列:分布式事务、重复消费、顺序消费,我整理了一下
你知道的越多,你不知道的越多 点赞再看,养成习惯 GitHub上已经开源 https://github.com/JavaFamily 有一线大厂面试点脑图、个人联系方式和人才交流群,欢迎Star和完善 前言 消息队列在互联网技术存储方面使用如此广泛,几乎所有的后端技术面试官都要在消息队列的使用和原理方面对小伙伴们进行360°的刁难。 作为一个在互联网公司面一次拿一次Offer的面霸...
Python爬虫爬取淘宝,京东商品信息
小编是一个理科生,不善长说一些废话。简单介绍下原理然后直接上代码。 使用的工具(Python+pycharm2019.3+selenium+xpath+chromedriver)其中要使用pycharm也可以私聊我selenium是一个框架可以通过pip下载 pip installselenium -ihttps://pypi.tuna.tsinghua.edu.cn/simple/ ...
阿里程序员写了一个新手都写不出的低级bug,被骂惨了。
这种新手都不会范的错,居然被一个工作好几年的小伙子写出来,差点被当场开除了。
Java工作4年来应聘要16K最后没要,细节如下。。。
前奏: 今天2B哥和大家分享一位前几天面试的一位应聘者,工作4年26岁,统招本科。 以下就是他的简历和面试情况。 基本情况: 专业技能: 1、&nbsp;熟悉Sping了解SpringMVC、SpringBoot、Mybatis等框架、了解SpringCloud微服务 2、&nbsp;熟悉常用项目管理工具:SVN、GIT、MAVEN、Jenkins 3、&nbsp;熟悉Nginx、tomca...
SpringBoot2.x系列教程(三十六)SpringBoot之Tomcat配置
Spring Boot默认内嵌的Tomcat为Servlet容器,关于Tomcat的所有属性都在ServerProperties配置类中。同时,也可以实现一些接口来自定义内嵌Servlet容器和内嵌Tomcat等的配置。 关于此配置,网络上有大量的资料,但都是基于SpringBoot1.5.x版本,并不适合当前最新版本。本文将带大家了解一下最新版本的使用。 ServerProperties的部分源...
Python绘图,圣诞树,花,爱心 | Turtle篇
每周每日,分享Python实战代码,入门资料,进阶资料,基础语法,爬虫,数据分析,web网站,机器学习,深度学习等等。 公众号回复【进群】沟通交流吧,QQ扫码进群学习吧 微信群 QQ群 1.画圣诞树 import turtle screen = turtle.Screen() screen.setup(800,600) circle = turtle.Turtle()...
作为一个程序员,CPU的这些硬核知识你必须会!
CPU对每个程序员来说,是个既熟悉又陌生的东西? 如果你只知道CPU是中央处理器的话,那可能对你并没有什么用,那么作为程序员的我们,必须要搞懂的就是CPU这家伙是如何运行的,尤其要搞懂它里面的寄存器是怎么一回事,因为这将让你从底层明白程序的运行机制。 随我一起,来好好认识下CPU这货吧 把CPU掰开来看 对于CPU来说,我们首先就要搞明白它是怎么回事,也就是它的内部构造,当然,CPU那么牛的一个东...
破14亿,Python分析我国存在哪些人口危机!
一、背景 二、爬取数据 三、数据分析 1、总人口 2、男女人口比例 3、人口城镇化 4、人口增长率 5、人口老化(抚养比) 6、各省人口 7、世界人口 四、遇到的问题 遇到的问题 1、数据分页,需要获取从1949-2018年数据,观察到有近20年参数:LAST20,由此推测获取近70年的参数可设置为:LAST70 2、2019年数据没有放上去,可以手动添加上去 3、将数据进行 行列转换 4、列名...
听说想当黑客的都玩过这个Monyer游戏(1~14攻略)
第零关 进入传送门开始第0关(游戏链接) 请点击链接进入第1关: 连接在左边→ ←连接在右边 看不到啊。。。。(只能看到一堆大佬做完的留名,也能看到菜鸡的我,在后面~~) 直接fn+f12吧 &lt;span&gt;连接在左边→&lt;/span&gt; &lt;a href="first.php"&gt;&lt;/a&gt; &lt;span&gt;←连接在右边&lt;/span&gt; o...
在家远程办公效率低?那你一定要收好这个「在家办公」神器!
相信大家都已经收到国务院延长春节假期的消息,接下来,在家远程办公可能将会持续一段时间。 但是问题来了。远程办公不是人在电脑前就当坐班了,相反,对于沟通效率,文件协作,以及信息安全都有着极高的要求。有着非常多的挑战,比如: 1在异地互相不见面的会议上,如何提高沟通效率? 2文件之间的来往反馈如何做到及时性?如何保证信息安全? 3如何规划安排每天工作,以及如何进行成果验收? ...... ...
作为一个程序员,内存和磁盘的这些事情,你不得不知道啊!!!
截止目前,我已经分享了如下几篇文章: 一个程序在计算机中是如何运行的?超级干货!!! 作为一个程序员,CPU的这些硬核知识你必须会! 作为一个程序员,内存的这些硬核知识你必须懂! 这些知识可以说是我们之前都不太重视的基础知识,可能大家在上大学的时候都学习过了,但是嘞,当时由于老师讲解的没那么有趣,又加上这些知识本身就比较枯燥,所以嘞,大家当初几乎等于没学。 再说啦,学习这些,也看不出来有什么用啊!...
这个世界上人真的分三六九等,你信吗?
偶然间,在知乎上看到一个问题 一时间,勾起了我深深的回忆。 以前在厂里打过两次工,做过家教,干过辅导班,做过中介。零下几度的晚上,贴过广告,满脸、满手地长冻疮。 再回首那段岁月,虽然苦,但让我学会了坚持和忍耐。让我明白了,在这个世界上,无论环境多么的恶劣,只要心存希望,星星之火,亦可燎原。 下文是原回答,希望能对你能有所启发。 如果我说,这个世界上人真的分三六九等,...
2020年全新Java学习路线图,含配套视频,学完即为中级Java程序员!!
新的一年来临,突如其来的疫情打破了平静的生活! 在家的你是否很无聊,如果无聊就来学习吧! 世上只有一种投资只赚不赔,那就是学习!!! 传智播客于2020年升级了Java学习线路图,硬核升级,免费放送! 学完你就是中级程序员,能更快一步找到工作! 一、Java基础 JavaSE基础是Java中级程序员的起点,是帮助你从小白到懂得编程的必经之路。 在Java基础板块中有6个子模块的学...
B 站上有哪些很好的学习资源?
哇说起B站,在小九眼里就是宝藏般的存在,放年假宅在家时一天刷6、7个小时不在话下,更别提今年的跨年晚会,我简直是跪着看完的!! 最早大家聚在在B站是为了追番,再后来我在上面刷欧美新歌和漂亮小姐姐的舞蹈视频,最近两年我和周围的朋友们已经把B站当作学习教室了,而且学习成本还免费,真是个励志的好平台ヽ(.◕ฺˇд ˇ◕ฺ;)ノ 下面我们就来盘点一下B站上优质的学习资源: 综合类 Oeasy: 综合...
爬取薅羊毛网站百度云资源
这是疫情期间无聊做的爬虫, 去获取暂时用不上的教程 import threading import time import pandas as pd import requests import re from threading import Thread, Lock # import urllib.request as request # req=urllib.request.Requ...
如何优雅地打印一个Java对象?
你好呀,我是沉默王二,一个和黄家驹一样身高,和刘德华一样颜值的程序员。虽然已经写了十多年的 Java 代码,但仍然觉得自己是个菜鸟(请允许我惭愧一下)。 在一个月黑风高的夜晚,我思前想后,觉得再也不能这么蹉跎下去了。于是痛下决心,准备通过输出的方式倒逼输入,以此来修炼自己的内功,从而进阶成为一名真正意义上的大神。与此同时,希望这些文章能够帮助到更多的读者,让大家在学习的路上不再寂寞、空虚和冷。 ...
雷火神山直播超两亿,Web播放器事件监听是怎么实现的?
Web播放器解决了在手机浏览器和PC浏览器上播放音视频数据的问题,让视音频内容可以不依赖用户安装App,就能进行播放以及在社交平台进行传播。在视频业务大数据平台中,播放数据的统计分析非常重要,所以Web播放器在使用过程中,需要对其内部的数据进行收集并上报至服务端,此时,就需要对发生在其内部的一些播放行为进行事件监听。 那么Web播放器事件监听是怎么实现的呢? 01 监听事件明细表 名...
3万字总结,Mysql优化之精髓
本文知识点较多,篇幅较长,请耐心学习 MySQL已经成为时下关系型数据库产品的中坚力量,备受互联网大厂的青睐,出门面试想进BAT,想拿高工资,不会点MySQL优化知识,拿offer的成功率会大大下降。 为什么要优化 系统的吞吐量瓶颈往往出现在数据库的访问速度上 随着应用程序的运行,数据库的中的数据会越来越多,处理时间会相应变慢 数据是存放在磁盘上的,读写速度无法和内存相比 如何优化 设计...
HTML5适合的情人节礼物有纪念日期功能
前言 利用HTML5,css,js实现爱心树 以及 纪念日期的功能 网页有播放音乐功能 以及打字倾诉感情的画面,非常适合情人节送给女朋友 具体的HTML代码 具体只要修改代码里面的男某某和女某某 文字段也可自行修改,还有代码下半部分的JS代码需要修改一下起始日期 注意月份为0~11月 也就是月份需要减一。 当然只有一部分HTML和JS代码不够运行的,文章最下面还附加了完整代码的下载地址 &lt;!...
相关热词 c#导入fbx c#中屏蔽键盘某个键 c#正态概率密度 c#和数据库登陆界面设计 c# 高斯消去法 c# codedom c#读取cad文件文本 c# 控制全局鼠标移动 c# temp 目录 bytes初始化 c#
立即提问