Anupam Agnihotri
Anupam Agnihotri

Reputation: 292

special characters and chinese fonts inserting in jsp page not working in spring controller

abc.jsp page. i am trying to insert chines fonts in the form.

<!DOCTYPE html>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ page language="java" contentType="text/html; charset=utf-8" 
    pageEncoding="utf-8"%>
<html lang="en">

<head>
 <meta http-equiv="content-type" content="text/html; charset=utf-8" />

<form id="bform"  action="addemo" method="POST" enctype="multipart/form-data"  class='form-group' accept-charset="utf-8">
                            <div class='form-group'>
                                <label>Book Image</label> <input type='file' name="file"
                                    class='btn' required="required" id="image_file"
                                    onchange="return validateimage();"> <img
                                    src="img/user_default_large.png" alt="" id="uploadPreview"
                                    style="height: 130px; width: 21%;">
                            </div>
                            <div class='form-group'>
                                <label>Book Title</label> <input type='text' name='title'
                                    class='form-control'  placeholder='Title' required="required">
                            </div>
                            <div class='form-group'>
                                <input type='Submit' name='cat_img' value='Add'
                                    class='btn btn-success'> <input type='reset'
                                    name='cat_img' value='Cancel' class='btn btn-primary'>
                            </div>
                        </form>

In the above form when i am adding chinese fonts "你好" and submitting the form request goes to controller.

@RequestMapping(value = "addemo", method = RequestMethod.POST)
    public JSONObject view(HttpServletRequest request,@Valid Books model, BindingResult results,
            @RequestPart(name = "file", required = false) MultipartFile image) throws ExecutionException, UnsupportedEncodingException {
        request.setCharacterEncoding("utf-8");
        String username = request.getParameter("title");
        System.out.println("encoding: "+request.getCharacterEncoding());
        System.out.println("received: "+username);
        System.out.println("received: "+username);
        JSONObject jsonObject = new JSONObject();
        System.out.println(model.getTitle());

i am getting this on my console encoding: utf-8 received: 你好 received: 你好 你好 你好

How should i get the utf-8 encoded data in a string params . please explain.

Upvotes: 0

Views: 754

Answers (1)

manjari.rastogi
manjari.rastogi

Reputation: 48

You need to look at UTF-8 support in the following areas:

URLs, Apache, HTML, JavaScript, POST data File download, JSPs, Java code, Tomcat, Oracle, File system

Go through the following link that might help u :- http://blogs.warwick.ac.uk/kieranshaw/entry/utf-8_internationalisation_with/

Upvotes: 1

Related Questions