java - java中如何从字符串中获取正确的特殊字符?

标签 java string stringbuffer jdom-2

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

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

    我的 Controller 方法..

    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>

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

最佳答案

在 jsp 中设置默认编码。应该可以。

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

关于java - java中如何从字符串中获取正确的特殊字符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20944874/

相关文章:

java - 正则表达式 - 任意顺序的单词

c++ - 如何使用 C++ 字符串将大写辅音替换为相应的小写辅音?

Java smack/Android asmack RosterListener

java - org.postgresql.util.PSQLException : FATAL: no pg_hba. 主机的 conf 条目

java - 由 : java. sql.SQLSyntaxErrorException 引起:ORA-01722:JPA HIBERNATE HQL 中的数字无效

java - SAX 回调不更新全局字符串缓冲区

java - Java中如何使用StringBuilder读取大文本文件?

java - 无法从 Java 程序执行 shell 脚本

Java String.codePointAt 返回意外值

java - 我可以将整数值附加到 stringbuilder 吗?