簡體   English   中英

如何從Java字符串中獲取適當的特殊字符?

[英]How to get proper special character from string in java?

  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>

當它顯示該時間時,它會顯示正確的特殊字符,但是當單擊保存按鈕時,它會更改垃圾字符中String的值。 如何解決這個問題呢。

在您的jsp中設置默認編碼。 那應該做。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM