Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/319.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 如何将变量放入OGNL标记中_Java_Struts2_Session Variables_Ognl - Fatal编程技术网

Java 如何将变量放入OGNL标记中

Java 如何将变量放入OGNL标记中,java,struts2,session-variables,ognl,Java,Struts2,Session Variables,Ognl,该列表可能包含多个问题对象,因此我将其设置为每页显示5个问题。我的问题是(例如)用户可能从第4页转到第2页,我想重新填写用户在第2页单击的答案。所以在action类中,我创建了一个HashMap,并将问题id(qid)和回答的问题(如ans2)放入该映射中,然后将该映射放入名为“map”的会话中 在上面的代码中,我使用 Question 1 (RadioButton) Answer 1 (RadioButton) Answer 2 (RadioButton) Answer 3 Question

该列表可能包含多个问题对象,因此我将其设置为每页显示5个问题。我的问题是(例如)用户可能从第4页转到第2页,我想重新填写用户在第2页单击的答案。所以在action类中,我创建了一个HashMap,并将问题id(qid)和回答的问题(如ans2)放入该映射中,然后将该映射放入名为“map”的会话中

在上面的代码中,我使用

Question 1
(RadioButton) Answer 1
(RadioButton) Answer 2
(RadioButton) Answer 3

Question 2
(RadioButton) Answer 1
(RadioButton) Answer 2
(RadioButton) Answer 3

.
.
.
我尝试将参数设置为

name="$(questions.qid)"

但它不起作用。请指导我如何生成参数变量。

要填充您的问题,您需要使用

根据您的描述创建的问题类

Map<String, String> map = new HashMap<String, String>();
公开课问题{
私有字符串名称;
私有字符串ans1;
私有字符串ans2;
私有字符串ans3;
//这里是盖特斯二传手
}
私人问题清单;
//getters setters在这里提问
确保在返回结果之前初始化问题

public class Question {
    private  String name;
    private  String ans1;
    private  String ans2;
    private  String ans3;

    //getters setters here
}

private List<Question> myQuestions;
//getters setters here for questions
publicstringexecute(){
myQuestions=new ArrayList();
添加(新问题(“问题1”、“问题1”、“问题2”、“问题3”);
添加(新问题(“问题2”、“问题1”、“问题2”、“问题3”);
//测试结果,映射不应为空
地图放置(“问题1”、“回答1”);
地图放置(“问题2”、“答案2”);
会议.付诸表决(“地图”,地图);
在本例中,由于会话映射值,第一个收音机将被选中,第二个收音机将被取消选中


表单的输入元素通过名称绑定到操作。如果在提交表单时需要获取值,则需要使用索引属性名称。

要填充问题,需要使用

根据您的描述创建的问题类

Map<String, String> map = new HashMap<String, String>();
公开课问题{
私有字符串名称;
私有字符串ans1;
私有字符串ans2;
私有字符串ans3;
//这里是盖特斯二传手
}
私人问题清单;
//getters setters在这里提问
确保在返回结果之前初始化问题

public class Question {
    private  String name;
    private  String ans1;
    private  String ans2;
    private  String ans3;

    //getters setters here
}

private List<Question> myQuestions;
//getters setters here for questions
publicstringexecute(){
myQuestions=new ArrayList();
添加(新问题(“问题1”、“问题1”、“问题2”、“问题3”);
添加(新问题(“问题2”、“问题1”、“问题2”、“问题3”);
//测试结果,映射不应为空
地图放置(“问题1”、“回答1”);
地图放置(“问题2”、“答案2”);
会议.付诸表决(“地图”,地图);
在本例中,由于会话映射值,第一个收音机将被选中,第二个收音机将被取消选中

表单的输入元素通过其名称绑定到操作。如果在提交表单时需要获取值,则需要使用索引属性名称

Map<String, String> map = new HashMap<String, String>();
public class Question {
    private  String name;
    private  String ans1;
    private  String ans2;
    private  String ans3;

    //getters setters here
}

private List<Question> myQuestions;
//getters setters here for questions
public String execute(){
  myQuestions = new ArrayList<Question>();
  myQuestions.add(new Question("Question1", "ans1", "ans2","ans3"));
  myQuestions.add(new Question("Question2","ans1", "ans2","ans3"));

  //test results, map should not be empty
  map.put("Question1", "ans1");
  map.put("Question2", "ans2");
  session.put("map", map);