简体   繁体   English

如何从Java字符串中获取适当的特殊字符?

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

  1. I am setting a special character in DataModel. 我在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.. 我的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>

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. 当它显示该时间时,它会显示正确的特殊字符,但是当单击保存按钮时,它会更改垃圾字符中String的值。 How to solve this problem. 如何解决这个问题呢。

Set default encoding in your jsp. 在您的jsp中设置默认编码。 That should do. 那应该做。

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