[英]How to get proper special character from string in java?
我在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.