本文介绍了上传到服务器后,页面上只有一个getter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个致力于Struts2框架的网站.它在我的本地计算机上可以正常工作,但是当我将其上传到远程服务器(托管)时,一些吸气剂和吸气剂就不再呼唤了.例如:

I have a web site working on Struts2 framework. It works fine on my local computer, but when I've uploaded it to the remote server (hosting) some getters and setters became not calling. For example:

操作:ForecastAction.java

JSP:Forecast.jsp

这是Forecast.jsp

This is forecast.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html>
...
 <span><s:property value="day" /></span>
 <span><s:property value="month" /></span>
 <span class="week_day"><s:property value="weekday" /></span>
 ...

这是ForecastAction.java

public class ForecastAction extends ActionSupport {

    private  String day, month, weekday;
    ... (other variables)

    public String getDay() {
        System.out.println("Ask for day");
        return day;
    }

    public void setDay(String day) {
        this.day = day;
    }

    public String getMonth() {
        System.out.println("Ask for month");
        return month;
    }

    public void setMonth(String month) {
        this.month = month;
    }

    public String getWeekday() {
        return weekday;
    }

    public void setWeekday(String weekday) {
        this.weekday = weekday;
    }
    ... (other setters and getters)
    public String execute(){
            ... (calculcating parameters)
            return SUCCESS;
    }
}

在我的本地计算机上,我可以看到所有值(日,月和周日),但是远程服务器仅返回到jsp的日值.在我看来,这些属性之间没有区别,但支撑仅显示一天.我已经检查过,该操作(在远程服务器上)会计算所有值,因此变量不是空的.问题在于,吸气剂不是由支撑杆来调用的.

On my local computer I could see all values (day, month and weekday), but remote server returns to jsp only day value. In my opinion, there is no difference between these properties, but struts shows only day. I've checked, that action (on remote server) calculates all values, so the variables are not empty. The problem is that getters are not calling by struts.

在我的应用程序的其他操作中也观察到相同的问题:设置器setPassword()不起作用,但setLogin()在授权操作中工作正常. (它只有两个二传手).

The same problem was observed in other action of my application: setter setPassword() doesn't work, but setLogin() works fine in authorization action. (It has only two setters).

UPD:

当我像这样在jsp中更改日期和月份时:

When I change day and month in jsp like this:

<span><s:property value="%{#day}"/></span>
<span><s:property value="%{#month}"/></span>

我开始正确地看到工作日.似乎,支撑杆只显示出他喜欢的第一属性:)再也没有.

I begin see weekday correctly. It seems, that struts shows ONLY FIRST property he likes:) And no more.

JSP Debug:
Struts has detected an unhandled exception:
1.permission can't be null

2.actionErrors

3.Caught an exception while getting the property values of Weather.Action.Public.ForecastAction@749f6da7

4.An exception occurred processing JSP page /forecast.jsp at line 3 1: <%@ page contentType="text/html;charset=UTF-8" language="java" %> 2: <%@ taglib prefix="s" uri="/struts-tags" %> 3: 4: 5: 6: Stacktrace:

Stacktraces

org.apache.jasper.JasperException: An exception occurred processing JSP page /forecast.jsp at line 3 1: <%@ page contentType="text/html;charset=UTF-8" language="java" %> 2: <%@ taglib prefix="s" uri="/struts-tags" %> 3: 4: 5: 6: Stacktrace:
  1)Caught an exception while getting the property values of  Weather.Action.Public.ForecastAction@30aa119a - Class: ognl.ObjectPropertyAccessor File: ObjectPropertyAccessor.java Method: getPossibleProperty Line: 69 - ognl/ObjectPropertyAccessor.java:69:-1
      2)actionErrors - Class: ognl.ObjectPropertyAccessor File:                ObjectPropertyAccessor.java Method: getPossibleProperty Line: 69 - ognl/ObjectPropertyAccessor.java:69:-1
         3)ognl.OgnlException: actionErrors [java.lang.NullPointerException: permission can't be null]
             4)java.lang.NullPointerException: permission can't be null

/UDP

您能帮我什么事吗?

也许需要下一个文件:

这是我的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>

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

<package name="public" namespace="/" extends="struts-default">
... (other actions)
    <action name="forecast" class="Weather.Action.Public.ForecastAction" method="execute">
        <result name="success">/forecast.jsp</result>
        <result name="error">/Error.jsp</result>
    </action>
... (other actions)
</package>
...(other package)
</struts>

和web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>Weather</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.ng.filter.StrutsPrepareAndExecuteFilter</filter- class>
</filter>

<filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

<servlet>
    <servlet-name>StartTimerServlet</servlet-name>
    <display-name>StartTimerServlet</display-name>
    <servlet-class>Weather.Service.StartTimerServlet</servlet-class>
    <load-on-startup>0</load-on-startup>
</servlet>

</web-app>

推荐答案

这可能是struts 2.3.1.1中的错误. Java安全性启用后,OGNL 3.0.3和某些应用程序服务器

It may be a bug in struts 2.3.1.1. and OGNL 3.0.3 and some application servers when java security is enabled

请参阅

https://issues.apache.org/jira/browse/OGNL-176

https://issues.apache.org/jira/browse/WW-3746

我建议您将Struts升级到最新版本

I suggest you upgrade your struts to last version

这篇关于上传到服务器后,页面上只有一个getter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 10:01