How to get proper special character from string in java?

人走茶凉 提交于 2020-02-25 02:13:07

问题


  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:


Set default encoding in your jsp. That should do.

<%@ page language="java" pageEncoding="utf8" contentType="text/html;charset=UTF-8" %>


来源:https://stackoverflow.com/questions/20944874/how-to-get-proper-special-character-from-string-in-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!