当前位置: 首页 > 面试题库 >

Struts2.3.12 junit4测试用例请求和会话为空

窦宏旷
2023-03-14
问题内容

但是我已经没有struts2-spring插件,也没有在应用程序中使用spring。

我有3个测试用例,其中2个在请求为null时失败,一个在会话为null时失败

第一个堆栈跟踪

java.lang.NullPointerException
    at org.apache.struts2.interceptor.MessageStoreInterceptor.before(MessageStoreInterceptor.java:228)
    at org.apache.struts2.interceptor.MessageStoreInterceptor.intercept(MessageStoreInterceptor.java:193)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
    at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:54)
    at actions.TestIoOptimizationAction.login(TestIoOptimizationAction.java:29)

对应于

            Collection actionErrors = (Collection) session.get(actionErrorsSessionKey);

第二和第三测试堆栈跟踪

java.lang.NullPointerException
    at org.apache.struts2.impl.StrutsActionProxy.getErrorMessage(StrutsActionProxy.java:69)
    at com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:185)
    at org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:63)
    at org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:39)
    at com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:58)
    at org.apache.struts2.StrutsJUnit4TestCase.getActionProxy(StrutsJUnit4TestCase.java:149)

对应于

        String contextPath = ServletActionContext.getRequest().getContextPath();

我相信存在一些依赖问题。我尝试过删除一些依赖项,并一并删除,但是都没有用。

这是我的POM的样子:

<dependencies>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jsp-api</artifactId>
            <version>2.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.paypal.sdk</groupId>
            <artifactId>rest-api-sdk</artifactId>
            <version>0.7.1</version>
        </dependency>
        <dependency>
            <groupId>net.sourceforge.htmlunit</groupId>
            <artifactId>htmlunit</artifactId>
            <version>2.12</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.0</version>
            <type>jar</type>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>commons-beanutils</groupId>
            <artifactId>commons-beanutils-core</artifactId>
            <version>1.8.3</version>
        </dependency>
        <dependency>
            <groupId>javax.mail</groupId>
            <artifactId>mail</artifactId>
            <version>1.4.5</version>
        </dependency>
        <dependency>
            <groupId>commons-lang</groupId>
            <artifactId>commons-lang</artifactId>
            <version>2.4</version>
        </dependency>
        <dependency>
            <groupId>javax.persistence</groupId>
            <artifactId>persistence-api</artifactId>
            <version>1.0</version>
            <type>jar</type>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.6</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>${hibernate.version}</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-validator</artifactId>
            <version>4.0.0.GA</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-c3p0</artifactId>
            <version>${hibernate.version}</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.6.1</version>
        </dependency>

        <dependency>
            <groupId>org.apache.tiles</groupId>
            <artifactId>tiles-servlet</artifactId>
            <version>2.1.4</version>
        </dependency>
        <dependency>
            <groupId>org.apache.tiles</groupId>
            <artifactId>tiles-jsp</artifactId>
            <version>2.1.4</version>
        </dependency>

        <dependency>
            <groupId>org.apache.struts</groupId>
            <artifactId>struts2-core</artifactId>
            <version>${struts.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.struts</groupId>
            <artifactId>struts2-json-plugin</artifactId>
            <version>${struts.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.struts</groupId>
            <artifactId>struts2-tiles-plugin</artifactId>
            <version>${struts.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.struts</groupId>
            <artifactId>struts2-junit-plugin</artifactId>
            <version>${struts.version}</version>
        </dependency>


        <dependency>
            <groupId>joda-time</groupId>
            <artifactId>joda-time</artifactId>
            <version>2.1</version>
        </dependency>
        <dependency>
            <groupId>org.quartz-scheduler</groupId>
            <artifactId>quartz</artifactId>
            <version>1.7.3</version>
        </dependency>

        <!--        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <scope>test</scope>
        </dependency>-->

        <dependency>
            <groupId>commons-collections</groupId>
            <artifactId>commons-collections</artifactId>
            <version>3.2.1</version>
            <type>jar</type>
        </dependency>
        <dependency>
            <groupId>org.jboss.spec</groupId>
            <artifactId>jboss-javaee-6.0</artifactId>
            <version>1.0.0.Final</version>
            <type>pom</type>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.myfaces.core</groupId>
            <artifactId>myfaces-api</artifactId>
            <version>2.1.11</version>
        </dependency>

        <dependency>
            <groupId>net.sf.jasperreports</groupId>
            <artifactId>jasperreports</artifactId>
            <version>3.7.5</version>
        </dependency>
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>2.2.4</version>
        </dependency>
        <dependency>
            <groupId>xml-apis</groupId>
            <artifactId>xml-apis</artifactId>
            <version>1.4.01</version>
        </dependency>            
    </dependencies>
<properties>
        <struts.version>2.3.12</struts.version>
        <hibernate.version>3.6.10.Final</hibernate.version>
        <struts.jquery.version>3.5.1</struts.jquery.version>
        <netbeans.compile.on.save>all</netbeans.compile.on.save>
        <netbeans.hint.deploy.server>Tomcat</netbeans.hint.deploy.server>
    </properties>

更新 -测试看起来像

@Test
public void login() throws Exception {
    request.setParameter("email", "nitin.cool4urchat@gmail.com");
    request.setParameter("password", "22");
    ActionProxy proxy = getActionProxy("login");
    String result = proxy.execute();
    assertEquals("success", result);
    System.out.println(response.getContentAsString());
}

@Test
public void testView() throws Exception {
    ActionProxy proxy = getActionProxy("/optimize/view");
    String result = proxy.execute();
    assertEquals("success", result);
    System.out.println(response.getContentAsString());

    proxy = getActionProxy("/optimize/view/23");
    result = proxy.execute();
    assertEquals("success", result);
    System.out.println(response.getContentAsString());

    proxy = getActionProxy("/optimize/view/110");
    result = proxy.execute();
    assertEquals("success", result);
    System.out.println(response.getContentAsString());
}

@Test
public void testSave() throws Exception {
    request.setContent("{\"id\":\"1\",\"name\":\"nitin\"}".getBytes());
    request.addHeader("Content-Type", "application/json");
    request.setMethod("POST");

    ActionProxy proxy = getActionProxy("/save");
    actions.IoOptimizationAction myAct = (actions.IoOptimizationAction) proxy.getAction();

    String result = proxy.execute();

    assertEquals("success", result);
    System.out.println(response.getContentAsString());
}

更新 我按照建议将测试更改为executeAction,因此,第二个测试现在看起来像

 @Test
    public void testView() throws Exception {
        System.out.println(ActionContext.getContext());
        System.out.println(executeAction("optimize/view"));
}

错误stacktrace是:

[2013-10-29 14:50:38.766] [ WARN] MockServletContext.getRealPath:298 - Couldn't determine real path of resource class path resource [org/apache/struts2/dispatcher/error_en_US.ftl]
java.io.FileNotFoundException: class path resource [org/apache/struts2/dispatcher/error_en_US.ftl] cannot be resolved to URL because it does not exist
    at org.springframework.core.io.ClassPathResource.getURL(ClassPathResource.java:179)
    at org.springframework.core.io.AbstractFileResolvingResource.getFile(AbstractFileResolvingResource.java:48)
    at org.springframework.mock.web.MockServletContext.getRealPath(MockServletContext.java:295)
    at freemarker.cache.WebappTemplateLoader.findTemplateSource(WebappTemplateLoader.java:129)
    at freemarker.cache.MultiTemplateLoader.findTemplateSource(MultiTemplateLoader.java:111)
    at freemarker.cache.TemplateCache.acquireTemplateSource(TemplateCache.java:646)
    at freemarker.cache.TemplateCache.findTemplateSource(TemplateCache.java:622)
    at freemarker.cache.TemplateCache.getTemplate(TemplateCache.java:346)
    at freemarker.cache.TemplateCache.getTemplate(TemplateCache.java:235)
    at freemarker.template.Configuration.getTemplate(Configuration.java:578)
    at freemarker.template.Configuration.getTemplate(Configuration.java:543)
    at org.apache.struts2.dispatcher.Dispatcher.sendError(Dispatcher.java:841)
    at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:569)
    at org.apache.struts2.StrutsJUnit4TestCase.executeAction(StrutsJUnit4TestCase.java:128)
    at actions.TestIoOptimizationAction.testView(TestIoOptimizationAction.java:44)
    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 org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
    at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
    at junit.framework.JUnit4TestAdapter.run(JUnit4TestAdapter.java:39)
    at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(JUnitTestRunner.java:520)
    at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.launch(JUnitTestRunner.java:1060)
    at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(JUnitTestRunner.java:911)
[2013-10-29 14:50:38.810] [ WARN] MockServletContext.getRealPath:298 - Couldn't determine real path of resource class path resource [org/apache/struts2/dispatcher/error_en.ftl]
java.io.FileNotFoundException: class path resource [org/apache/struts2/dispatcher/error_en.ftl] cannot be resolved to URL because it does not exist
    at org.springframework.core.io.ClassPathResource.getURL(ClassPathResource.java:179)
    at org.springframework.core.io.AbstractFileResolvingResource.getFile(AbstractFileResolvingResource.java:48)
    at org.springframework.mock.web.MockServletContext.getRealPath(MockServletContext.java:295)
    at freemarker.cache.WebappTemplateLoader.findTemplateSource(WebappTemplateLoader.java:129)
    at freemarker.cache.MultiTemplateLoader.findTemplateSource(MultiTemplateLoader.java:111)
    at freemarker.cache.TemplateCache.acquireTemplateSource(TemplateCache.java:646)
    at freemarker.cache.TemplateCache.findTemplateSource(TemplateCache.java:622)
    at freemarker.cache.TemplateCache.getTemplate(TemplateCache.java:346)
    at freemarker.cache.TemplateCache.getTemplate(TemplateCache.java:235)
    at freemarker.template.Configuration.getTemplate(Configuration.java:578)
    at freemarker.template.Configuration.getTemplate(Configuration.java:543)
    at org.apache.struts2.dispatcher.Dispatcher.sendError(Dispatcher.java:841)
    at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:569)
    at org.apache.struts2.StrutsJUnit4TestCase.executeAction(StrutsJUnit4TestCase.java:128)
    at actions.TestIoOptimizationAction.testView(TestIoOptimizationAction.java:44)
    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 org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
    at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
    at junit.framework.JUnit4TestAdapter.run(JUnit4TestAdapter.java:39)
    at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(JUnitTestRunner.java:520)
    at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.launch(JUnitTestRunner.java:1060)
    at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(JUnitTestRunner.java:911)
[2013-10-29 14:50:39.127] [ WARN] MockServletContext.getRealPath:298 - Couldn't determine real path of resource class path resource [org/apache/struts2/dispatcher/error.ftl]
java.io.FileNotFoundException: class path resource [org/apache/struts2/dispatcher/error.ftl] cannot be resolved to absolute file path because it does not reside in the file system: jar:file:/C:/Users/hp/.m2/repository/org/apache/struts/struts2-core/2.3.12/struts2-core-2.3.12.jar!/org/apache/struts2/dispatcher/error.ftl
    at org.springframework.util.ResourceUtils.getFile(ResourceUtils.java:204)
    at org.springframework.core.io.AbstractFileResolvingResource.getFile(AbstractFileResolvingResource.java:52)
    at org.springframework.mock.web.MockServletContext.getRealPath(MockServletContext.java:295)
    at freemarker.cache.WebappTemplateLoader.findTemplateSource(WebappTemplateLoader.java:129)
    at freemarker.cache.MultiTemplateLoader.findTemplateSource(MultiTemplateLoader.java:111)
    at freemarker.cache.TemplateCache.acquireTemplateSource(TemplateCache.java:646)
    at freemarker.cache.TemplateCache.findTemplateSource(TemplateCache.java:622)
    at freemarker.cache.TemplateCache.getTemplate(TemplateCache.java:346)
    at freemarker.cache.TemplateCache.getTemplate(TemplateCache.java:235)
    at freemarker.template.Configuration.getTemplate(Configuration.java:578)
    at freemarker.template.Configuration.getTemplate(Configuration.java:543)
    at org.apache.struts2.dispatcher.Dispatcher.sendError(Dispatcher.java:841)
    at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:569)
    at org.apache.struts2.StrutsJUnit4TestCase.executeAction(StrutsJUnit4TestCase.java:128)
    at actions.TestIoOptimizationAction.testView(TestIoOptimizationAction.java:44)
    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 org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
    at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
    at junit.framework.JUnit4TestAdapter.run(JUnit4TestAdapter.java:39)
    at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(JUnitTestRunner.java:520)
    at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.launch(JUnitTestRunner.java:1060)
    at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(JUnitTestRunner.java:911)
<html>
<head>
    <title>Struts Problem Report</title>
    <style>
        pre {
            margin: 0;
            padding: 0;
        }    
    </style>
</head>
<body>
    <h2>Struts Problem Report</h2>
    <p>
    Struts has detected an unhandled exception:
    </p>


<div id="exception-info">
<table>
    <tr>
        <td><strong>Messages</strong>:</td>
        <td>
        </td>
    </tr>
    <tr>
        <td><strong>File</strong>:</td>
        <td>org/apache/struts2/impl/StrutsActionProxy.java</td>
    </tr>
    <tr>
        <td><strong>Line number</strong>:</td>
        <td>69</td>
    </tr>

</table>
</div>


<div id="stacktraces">
<hr />
<h3>Stacktraces</h3>
<div class="stacktrace" style="padding-left: 0em">
    <strong>java.lang.NullPointerException</strong>
    <div>
    <pre>
    org.apache.struts2.impl.StrutsActionProxy.getErrorMessage(StrutsActionProxy.java:69)
    com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:185)
    org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:63)
    org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:39)
    com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:58)
    org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:536)
    org.apache.struts2.StrutsJUnit4TestCase.executeAction(StrutsJUnit4TestCase.java:128)
    actions.TestIoOptimizationAction.testView(TestIoOptimizationAction.java:44)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    java.lang.reflect.Method.invoke(Method.java:597)
    org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
    org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
    org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
    org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
    org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
    org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
    org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
    org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
    org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
    org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
    org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
    org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
    org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
    org.junit.runners.ParentRunner.run(ParentRunner.java:236)
    junit.framework.JUnit4TestAdapter.run(JUnit4TestAdapter.java:39)
    org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(JUnitTestRunner.java:520)
    org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.launch(JUnitTestRunner.java:1060)
    org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(JUnitTestRunner.java:911)
    </pre>
    </div>
</div>
</div>

<div class="footer">
<hr />
<p>
You are seeing this page because development mode is enabled.  Development mode, or devMode, enables extra
debugging behaviors and reports to assist developers.  To disable this mode, set:
<pre>
  struts.devMode=false
</pre>
in your <code>WEB-INF/classes/struts.properties</code> file.
</p>
</div>
</body>
</html>

问题答案:

如果使用getActionProxy方法执行操作,则需要在调用上下文中设置新的会话映射。

ActionProxy actionProxy = getActionProxy("/action");
Map<String, Object> sessionMap = new HashMap<String, Object>();
actionProxy.getInvocation().getInvocationContext().setSession(sessionMap);
actionProxy.execute();

如果您不需要引用动作代理,则可以使用executeAction方法。请注意,这
executeAction将返回结果的实际输出,而不是execute方法返回的结果。



 类似资料:
  • 问题内容: 我正在使用请求模块(Python 2.5的版本0.10.0)。我已经弄清楚了如何将数据提交到网站上的登录表单并检索会话密钥,但是我看不到在后续请求中使用此会话密钥的明显方法。有人可以在下面的代码中填写省略号还是建议其他方法? 问题答案: 您可以使用以下方法轻松创建持久会话: 之后,请继续执行您的请求: 有关会话的更多信息,请访问:https : //requests.kennethre

  • 目前正在用Spring Boot 2.0.0.M4、Spring 5.0.0.RC4和Reactor 3.1.0.RC1进行反应性编程。 如果没有,这是计划好的吗? 谢谢你抽出时间。

  • 在我的ATG应用程序中,当我使用checkFormRedirect将用户重定向到带有一些参数的jsp页面时,我得到的参数为NULL。请参阅下面的FormHandler代码: UserFormHandler: test.jsp: 此外,我尝试在formHandler中使用变量并设置值,但仍然得到的值为NULL。能不能帮点忙。

  • 问题内容: 我刚刚启动了一个简单的Java测试项目,该项目使用Hibernate管理某些实体,并提供REST接口来操纵这些对象并提供一些其他业务逻辑。REST接口是使用RESTEasy和Jetty创建的。 到目前为止,一切工作正常,但是我感觉我实际上写了太多样板代码。由于我在这些Java框架中没有太多经验,所以我只是想知道是否有人可以给我提示如何改善这种情况。 每个请求创建hibernate会话

  • 任何web应用程序的核心内容之一是控制和维持用户交互状态的机制。这通常被认为是会话管理,定义为一系列用于管理用户和web应用系统交互状态的措施。这广泛覆盖了从用户如何认证到他们登出时发生的任何事情。 HTTP是一个无状态的协议,意味着web服务器在相应用户请求时不需要联系其他请求。但甚至有时是简单的应用程序逻辑也可能需要通过一个“会话”来关联用户发送的多个请求。这便需要第三方解决方案的介入,通过现

  • 问题内容: 我正在尝试使用Python请求登录LinkedIn: 我似乎无法使用此方法登录。我什至尝试在有效负载中使用csrf等,但是会话不是应该为您解决吗? 关于最后一行的注意事项:我使用标题来检查是否已成功登录。(如果我已经登录,则应该看到“ Welcome!| LinkedIn”,而我会看到“世界上最大的专业网络| LinkedIn”) 我想念什么吗? 问题答案: 我修改了一个网络抓取模板,