0

我有一个使用速度的 java we 应用程序。我通过使用 ureq.getParameter() 方法提取的 url 在第一页中获得了两个变量。具有速度容器的其他类之一,我需要将其中一个变量从 url 发送到此速度容器。我尝试在第二个类中创建第一个类的实例并使用 getVariable name 方法来做到这一点,但它不起作用。有人能告诉我我该怎么做吗?

第一类:

package org.olat.dispatcher;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.olat.core.gui.UserRequest;

public class RemoteLoginformDispatcher implements Dispatcher {

    private static final String PARAM_newUrl = "ret";
    private static String newURL;

    @Override
    public void execute(
            final HttpServletRequest request, 
            final HttpServletResponse response, 
            final String uriPrefix) {

        UserRequest ureq = null;

        try {
            ureq = new UserRequest(uriPrefix, request, response);
            newURL = ureq.getParameter(PARAM_newUrl);
        } catch () {
        }

    }

    public String getURL(){
        return newURL;
    }

}

第 2 类:

public class BaseChiefController extends DefaultChiefController implements ContentableChiefController {
    //Velocity container mainvc created here. It interacts with a html file. Removed the code that would not really matter

    //mainvc.contextPut("newURL", "something");
    //The below statement works. When I try with something, the something appears in the html file.
    mainvc.contextPut("newURL", myLogin.getURL());      

}
4

1 回答 1

1

To create an instance of another class, simply create a "public CLASSNAME" method, and inside define all class variables with the "this" modfier. Then, call out the function you wish to use from that method, and when you want to use the class, just do "new CLASSNAME(args);"

Although, I am not really sure I am understanding your question.

Maybe this is your answer. You can use variables from one class to another class by making the variable static, then doing "CLASSNAME.VARIABLENAME = WHATEVER".


EDITED:

Okay, so as far as I can tell, you are using a method to return a static value from the class, which is much slower than just doing "newURL", RemoteLoginformDispatcher.newURL);. Why not try this, as it is probably faster, and it should always work if newURL is defined. Otherwise, you have a different problem, and newURL is not being defined. If this is the case, try printing the caught Exception.

于 2012-09-03T02:36:59.500 回答