我有一個網站在Struts2框架上工作。它可以在我的本地計算機上正常工作,但是當我將它上傳到遠程服務器(託管)時,一些獲取者和設置者無法呼叫。 例如:上傳到服務器後,頁面上只有一個getter工作
操作:ForecastAction.java
JSP:forecast.jsp
這是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日值。在我看來,這些屬性沒有區別,但struts只顯示一天。我檢查過,(在遠程服務器上)這個動作計算所有的值,所以變量不是空的。問題是getter不是由struts調用的。
在我的應用程序的其他操作中觀察到同樣的問題:setter setPassword()
不起作用,但setLogin()
在授權操作中正常工作。 (它只有兩個setter)。
UPD:
當我更改日期和月份在JSP中:
<span><s:property value="%{#day}"/></span>
<span><s:property value="%{#month}"/></span>
我開始看到正確的工作日。看起來,struts只顯示他喜歡的第一個屬性:)而沒有更多。
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 [email protected]
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 [email protected] - 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>
getMonth到System.out.println(「Ask for month」+ month);你會在輸出中看到什麼?你會在那裏看到正確的月份嗎?! –
感謝您的關注,當我更改爲「System.out.println(」詢問月份「+月份);」沒有什麼變化。方法getMonth不被調用。 – user3262714
當我在jsp中更改日期和月份時,如下所示: '
' 我開始看到正確的工作日。看起來,struts只顯示他喜歡的第一個屬性:)而沒有更多。 – user3262714