从这个问题开始。
How to servlet println(); tag <c:forEach>
我试图通过javaservlet中的println来使代言模式成为可能。
我已经可以修复它,但是我发现所有泰语节目都像???????。 我尝试通过使用来修复 response.setContentType(“ text / html; charset = UTF-8”)和response.setCharacterEncoding(“ UTF-8”)或者我尝试使用jsp进行修复。但这不起作用。
这是我的引导程序模式代码
/员工
jsp代码。
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix = "fn" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Employees</title>
<jsp:include page="_header.jsp"></jsp:include>
</head>
<body>
<!-- Modal -->
<div class="modal fade" id="Modal" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
</div>
<div class="modal-body">
</div>
<div class="modal-footer">
</div>
</div>
</div>
</div>
<script>
$(document).ready(function(){
$('.modal-dlg').on('click',function(){
var dataURL = $(this).attr('href');
$('.modal-dialog').load(dataURL,function(){
$('#Modal').modal({show:true});
});
});
});
</script>
<!-- End Modal -->
<div class="wrapper">
<jsp:include page="_menu.jsp"></jsp:include>
<div class="container">
<div class="row">
<div id="title_bar" class="btn-toolbar print_hide">
<button class="btn btn-info btn-sm pull-right modal-dlg" href="./employees/view"
title="New Employee">
<span class="glyphicon glyphicon-user"> </span>New Employee</button>
</div>
</div>
</div>
<jsp:include page="_footer.jsp"></jsp:include>
</div>
</body>
</html>
/ employees / view = / view?type = employees
jsp代码
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix = "fn" %>
<form action="./employees/save_definition/-1" id="employees_form" class="form-horizontal" method="post" accept-charset="utf-8">
<div class="modal-content">
<div class="modal-header">
<div class="bootstap-dialog-header">
<div class="bootstrap-dialog-close-buttom" style="display: block;">
<button type="button" class="close" data-dismiss="modal">×</button>
<div class="bootstrap-dialog-title">ผู้ใช้ใหม่</div>
</div>
</div>
</div>
<div class="modal-body">
<div id="required_fields_message">Fields in red are required</div>
<ul id="error_message_box" class="error_message_box"></ul>
<fieldset id="employee_basic_info">
<div class="form-group form-group-sm">
<label for="users_name" class="required control-label col-xs-3">Username:</label>
<div class='col-xs-8'>
<input type="text" name="users_name" value="" class="form-control input-sm" />
</div>
</div>
<div class="form-group form-group-sm">
<label for="users_password" class="required control-label col-xs-3">Password:</label>
<div class='col-xs-8'>
<input type="text" name="users_password" value="" class="form-control input-sm" />
</div>
</div>
<div class="form-group form-group-sm">
<label for="reusers_password" class="required control-label col-xs-3">Re-Password:</label>
<div class='col-xs-8'>
<input type="text" name="re_password" value="" class="form-control input-sm" />
</div>
</div>
<div class="form-group form-group-sm">
<label for="users_gender" class="control-label col-xs-3">Gender:</label>
<div class='col-xs-8'>
<select name="users_gender" id="users_gender" class="form-control">
<option value="0" selected="selected">Gender</option>
<option value="1">Male</option>
<option value="2">Female</option>
</select>
</div>
</div>
<div class="form-group form-group-sm">
<label for="users_name_title" class="control-label col-xs-3">Name Title:</label>
<div class='col-xs-8'>
<select name="users_name_title" id="users_name_title" class="form-control">
<option value="0" selected="selected">Name Title</option>
<option value="1">Mr.</option>
<option value="2">Miss</option>
<option value="3">Mrs.</option>
</select>
</div>
</div>
<div class="form-group form-group-sm">
<label for="users_first_name" class="required control-label col-xs-3">First Name:</label>
<div class='col-xs-8'>
<input type="text" name="users_first_name" value="" class="form-control input-sm" />
</div>
</div>
<div class="form-group form-group-sm">
<label for="users_last_name" class="required control-label col-xs-3">Last Name:</label>
<div class='col-xs-8'>
<input type="text" name="users_last_name" value="" class="form-control input-sm" />
</div>
</div>
<div class="form-group form-group-sm">
<label for="users_group" class="required control-label col-xs-3">Group:</label>
<div class='col-xs-8'>
<select name="users_group" id="users_group" class="form-control">
<option value="0" selected="selected">Group</option>
<option value="1">Administrator</option>
<option value="2">User</option>
<option value="3">View</option>
</select>
</div>
</div>
<div class="form-group form-group-sm">
<label for="users_address1" class="control-label col-xs-3">Address1:</label>
<div class='col-xs-8'>
<input type="text" name="users_address1" value="" class="form-control input-sm" />
</div>
</div>
<div class="form-group form-group-sm">
<label for="users_address2" class="control-label col-xs-3">Address2:</label>
<div class='col-xs-8'>
<input type="text" name="users_address2" value="" class="form-control input-sm" />
</div>
</div>
<div class="form-group form-group-sm">
<label for="users_city" class="control-label col-xs-3">City:</label>
<div class='col-xs-8'>
<select name="users_city" id="users_city" class="form-control">
<option value="0" selected="selected">City</option>
</select>
</div>
</div>
<div class="form-group form-group-sm">
<label for="users_state" class="control-label col-xs-3">State:</label>
<div class='col-xs-8'>
<select name="users_state" id="users_state" class="form-control">
<option value="0" selected="selected">State</option>
</select>
</div>
</div>
<div class="form-group form-group-sm">
<label for="users_province" class="control-label col-xs-3">Province:</label>
<div class='col-xs-8'>
<select name="users_province" id="users_province" class="form-control">
<option value="0" selected="selected">Province</option>
<c:forEach items="${provincesList}" var="lists" >
<option value="${lists.provinceCode}">${lists.provinceNameTh}</option>
</c:forEach>
</select>
</div>
</div>
<div class="form-group form-group-sm">
<label for="users_zip" class="control-label col-xs-3">Zip:</label>
<div class='col-xs-8'>
<input type="text" name="users_zip" value="" class="form-control input-sm" />
</div>
</div>
<div class="form-group form-group-sm">
<label for="users_country" class="control-label col-xs-3">Country:</label>
<div class='col-xs-8'>
<select name="users_country" id="users_country" class="form-control">
<option value="0" selected="selected">Country</option>
</select>
</div>
</div>
<div class="form-group form-group-sm">
<label for="users_phone_number" class="control-label col-xs-3">Phone Number:</label>
<div class='col-xs-8'>
<input type="text" name="users_phone_number" value="" class="form-control input-sm" />
</div>
</div>
<div class="form-group form-group-sm">
<label for="users_email" class="control-label col-xs-3">Email:</label>
<div class='col-xs-8'>
<input type="text" name="users_email" value="" class="form-control input-sm" />
</div>
</div>
</fieldset>
</div>
<div class="modal-footer">
<div class="bootstrap-dialog-footer">
<div class="bootstrap-dialog-footer-buttons">
<button id="submit" class="btn btn-primary">Submit</button>
</div>
</div>
</div>
</div>
</form>
您可以看到我的员工引导程序表上没有泰语的问题,但是引导模式有泰语的问题。
答案 0 :(得分:0)
我发现此问题来自我的Servlet代码中的 PrintWriter pw = response.getWriter(); 。但是我不知道为什么。
viewServlet.java
@WebServlet(urlPatterns = { "/view" })
public class viewSerlvet extends HttpServlet {
private static final long serialVersionUID = 1L;
public viewSerlvet() {
super();
}
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
HttpSession session = request.getSession();
// Check User has logged on
userAccount loginedUser = myUtils.getLoginedUser(session);
// Not logged in
if (loginedUser == null) {
// Redirect to login page.
response.sendRedirect(request.getContextPath() + "/login");
return;
}
// Store info to the request attribute before forwarding.
request.setAttribute("user", loginedUser);
String errorString = null;
Connection conn = myUtils.getStoredConnection(request);
String typeQuerystring = request.getParameter("type");
String definitionIDQuerystring = request.getParameter("definitionid");
PrintWriter pw = response.getWriter();
if (definitionIDQuerystring == null) {
switch (typeQuerystring)
{
case "employees":
List<provinces> provincesList = null;
try {
provincesList = dbUtils.queryProvinces(conn);
} catch (SQLException e) {
e.printStackTrace();
errorString = e.getMessage();
}
request.setAttribute("provincesList", provincesList);
break;
case "customers":
break;
case "suppilers":
break;
case "stocklocation":
break;
case "categories":
break;
case "items":
break;
case "profile":
break;
default:
response.getWriter().print("Invalid Parameter!");
}
}
else {
switch (typeQuerystring)
{
case "employees":
break;
case "customers":
break;
case "suppilers":
break;
case "stocklocation":
break;
case "categories":
break;
case "items":
break;
case "profile":
break;
default:
response.getWriter().print("Invalid Parameter!");
}
}
// Store info in request attribute, before forward to views
request.setAttribute("errorString", errorString);
// Forward to /WEB-INF/views/productListView.jsp
RequestDispatcher dispatcher = request.getServletContext()
.getRequestDispatcher("/WEB-INF/views/viewView.jsp");
// .getRequestDispatcher("/WEB-INF/test.jsp");
dispatcher.forward(request, response);
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}
}