Only one getter works on the page after uploading to the server

人盡茶涼 提交于 2020-01-15 08:42:14

问题


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:

Action: ForecastAction.java

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>
 ...

This is 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;
    }
}

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.

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:

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

Could you help me, what can be wrong?

Maybe next files will be necessary:

This is my 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>

And 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>

回答1:


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

Please see

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

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

I suggest you upgrade your struts to last version



来源:https://stackoverflow.com/questions/22880555/only-one-getter-works-on-the-page-after-uploading-to-the-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!