How to get proper special character from string in

2019-07-16 19:17发布

  1. I am setting a special character in DataModel.
    My DataModel

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

    My controller method..

    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);
    }
    

    My JSP page..

<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>

when it display that time it displays correct special character but when click on save button that time it change the value of String in junk character How it happens I dnt get it. How to solve this problem.

1条回答
Bombasti
2楼-- · 2019-07-16 19:33

Set default encoding in your jsp. That should do.

<%@ page language="java" pageEncoding="utf8" contentType="text/html;charset=UTF-8" %>
查看更多
登录 后发表回答