簡體   English   中英

來自struts2動作類的方法未執行

[英]A method from struts2 action class is not executing

我正在將Webapp從Struts 2.0移植到2.3。 我無法使DynamicMethodInvocation正常工作。 我有一個帶有add()方法的動作類。 register!add.shtml上提交表單不會執行此方法。 我找不到任何原因。

這是我使用的罐子:

struts2-core-2.3.16.jar
xwork-core-2.3.16.jar
struts2-spring-plugin-2.3.16.jar

這是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>
    <constant name="struts.objectFactory" value="spring"/>
    <constant name="struts.devMode" value="true"/>
    <constant name="struts.url.includeParams" value="none" />
    <constant name="struts.enable.DynamicMethodInvocation" value="true"/>
    <constant name="struts.action.extension" value="shtml"/>

    <package name="item" extends="struts-default" strict-method-invocation="true">
        <action name="register" class="profileAction">
            <!--<result>/WEB-INF/jsp/register.jsp</result>-->
            <result name="success">/WEB-INF/jsp/register_success.jsp</result>
            <result name="input">/WEB-INF/jsp/register.jsp</result>
            <result name="error">/WEB-INF/jsp/register.jsp</result>
            <allowed-methods>execute,add,save</allowed-methods>
        </action>

還有一個簡單的struts-beans.xml 沒有其他文件,例如.properties

任何人?

PS這是動作代碼。 但我認為這並不重要。 我嘗試在第一行上設置斷點。 但是調試器只是沒有到達那里。

public String add() {
    try {
        StringBuilder sb = new StringBuilder();
        sb.append("<person>\n")
                .append("<fullname>").append(getLastName()).append(" ").append(getFirstName()).append("</fullname>\n")
                .append("<login>").append(getLogin()).append("</login>\n")
                .append("<email>").append(getLogin()).append("</email>\n")
                .append("<phone>").append(getPhone()).append("</phone>\n")
                .append("</person>\n");
        URL url = new URL(getCreatePersonURL());
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setRequestMethod("POST");
        connection.setDoOutput(true);
        connection.setRequestProperty("Content-Type", "application/xml; charset=utf8");
        OutputStreamWriter wr= new OutputStreamWriter(connection.getOutputStream());
        wr.write(sb.toString());
        InputStream content = connection.getInputStream();
        BufferedReader in = new BufferedReader(new InputStreamReader(content));

        String line;
        if ((line = in.readLine()) != null)
            if (!line.equalsIgnoreCase("<status>OK</status>")) {
                addActionError("Регистрация в данный момент не возможна"); // TODO обработка ошибок от zayavkaapi

                return Action.ERROR;
            }
    } catch (IOException e) {
        addActionError("Регистрация в данный момент не возможна"); // TODO обработка ошибок от zayavkaapi

        return Action.ERROR;
    }

    Customer c = new Customer();
    c.setKeyword(getKeyphrase());
    c.setPassword(getPassword());
    c.setLogin(getLogin());
    c.setEmail(getEmail());
    ContactPerson cp = new ContactPerson();
    cp.setFirstName(getFirstName());
    cp.setLastName(getLastName());
    cp.setMiddleName(getMiddleName());

    ArrayList<ContactInfo> cil = new ArrayList<ContactInfo>();
    ContactInfo ci = new ContactInfo();
    ci.setContactInfoTypeId("ADDRESS");// Адрес
    ci.setCountryId(getCountry());
    ci.setField2(getCity());
    cil.add(ci);

    ci = new ContactInfo();
    ci.setContactInfoTypeId("PHONE");// Телефон
    //String[] strings = getPhone().split(" ");
    ci.setField1(getCountryCode());
    ci.setField2(getCityCode());
    ci.setField3(getPhone());
    ci.setField4(getOfficePhone());
    //if (strings.length > 3)
    cil.add(ci);

    ci = new ContactInfo();
    ci.setContactInfoTypeId("EMAIL");// e-mail
    ci.setField1(getEmail());
    cil.add(ci);

    cp.setContactInfoList(cil);
    c.setMainContactPerson(cp);
    ArrayList<ContactPerson> cpl = new ArrayList<ContactPerson>();
    cpl.add(cp);
    c.setContactPersons(cpl);
    Long customerId = customerManager.createCustomer(c);
    customer = customerManager.getCustomerById(customerId);

    User user = new User(getLogin(), Md5Calc.MD5(getPassword()) , true, true, true, true, new GrantedAuthority[]{new GrantedAuthorityImpl("ROLE_CUSTOMER")});
    UsernamePasswordAuthenticationToken result = new UsernamePasswordAuthenticationToken(user, getLogin(), user.getAuthorities());
    SecurityContextHolder.getContext().setAuthentication(result);

    return Action.SUCCESS;
}

在此處發布代碼建議我將@SkipValidation批注add()add()方法。 它開始執行。 正如湯姆所建議的,我確實遇到了驗證錯誤,該錯誤未輸出到錯誤部分。 這使該方法無法執行。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM