Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/397.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java struts2操作类中的方法未执行_Java_Struts2 - Fatal编程技术网

Java struts2操作类中的方法未执行

Java struts2操作类中的方法未执行,java,struts2,Java,Struts2,我正在将一个webapp从struts2.0移植到2.3。我不能让动态的方法工作。 我有一个带有add()方法的action类在注册时提交表单!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" ?> &

我正在将一个webapp从struts2.0移植到2.3。我不能让动态的方法工作。 我有一个带有
add()
方法的action类
注册时提交表单!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>

在这里发布代码建议我将
@SkipValidation
注释添加到
add()
方法中。它开始执行。正如Tom所说,我确实遇到了一个验证错误,它没有输出到errors部分。这就阻止了方法的执行。

输出是什么?有错误吗?没有错误。调用
register.shtml
成功执行
execute()
方法。但是呼叫
注册!add.shtml
没有像我所期望的那样调用
add()
。它只是呈现为
定义的
register.jsp
,请发布您的操作代码您确定没有命中
错误
结果(这也是register.jsp)?您可能只是没有在生成的jsp中打印操作错误消息。
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;
}