2
  1. 我在 DataModel 中设置了一个特殊字符。
    我的数据模型

    public class LaunchModel implements Serializable {
    
        private List<LaunchModel> testquestionList;
        public LaunchModel() {
        testquestionList=new ArrayList<LaunchModel>();
        }
        //GETTER AND SETTER
    }
    

    我的控制器方法..

    private void setdefaultValues() {
    
        LaunchModel temp=new LaunchModel();
        List<LaunchModel> tempList=new ArrayList<LaunchModel>();
        temp.setQuestion("ΔLMN and ΔXYZ");
        tempList.add(temp);
        this.launchModel.setTestquestionList(tempList);
    }
    

    我的 JSP 页面..

<h:form id="addAssessmentFormId" enctype="multipart/form-data">
    <t:div id="main" forceId="true">
        <t:dataList id="questionList" var="question"
            value="#{launchPlayer.launchModel.testquestionList}" rowIndexVar="index"
            layout="unorderedList" forceId="true">

            <t:div>
            <h:outputText id="que" value="#{question.question}" />
                <h:inputTextarea id="que" value="#{question.question}" />
            </t:div>
        </t:dataList>
        <t:div style="text-align:center;">
            <h:commandButton value="save" action="#{launchPlayer.testsaveAssessment}"></h:commandButton>
        </t:div>
    </t:div>


</h:form>

当它显示该时间时,它会显示正确的特殊字符,但是当单击保存按钮时,它会更改垃圾字符中字符串的值它是如何发生的,我不明白。如何解决这个问题呢。

4

1 回答 1

3

在你的jsp中设置默认编码。应该这样做。

<%@ page language="java" pageEncoding="utf8" contentType="text/html;charset=UTF-8" %>
于 2014-01-06T07:20:45.530 回答