Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > Java Programming > Java Forum > Java / JSP ช่วยที่ครับ มีปัญหา เกี่ยวกับภาษาไทย ในการส่งและรับค่า ตอนอัพขึ้น Hosting



 

Java / JSP ช่วยที่ครับ มีปัญหา เกี่ยวกับภาษาไทย ในการส่งและรับค่า ตอนอัพขึ้น Hosting

 



Topic : 096846



โพสกระทู้ ( 40 )
บทความ ( 0 )



สถานะออฟไลน์




การทำงานคือ กรอกข้อมูลที่contactForm.jsp แล้ว ส่งพารามิตเตอร์ไป ที่ไฟล์ servletContact.java
แล้วนำค่าที่ได้ไป ส่งอีเมล์ และบันทึกลงฐานข้อมูล

ตอนผมใช้เครื่องตัวเองเป็นโฮสไม่มีปัญหาเรื่องภาษาไทยครับ ไม่ว่าจะบันทึกลงฐานข้อมูล หรือส่งอีเมลล์มา

แต่พออัพขึ้นโฮสติง มีปัญหา ภาษาไทย ที่ส่งมาจากหน้า contactForm.jsp ไปที่ servletContact.java เช่น ชื่อ-นามสกุล
พอบันทึกลงฐานข้อมูลจะกลายเป็น ??????????????
แต่ภาษาไทยที่มีอยู่แล้วในไฟล์ servletContact.java เช่น

Code
String textSubject = "การติดต่อสอบถามข้อมูลจากลูกค้า (Contacted from customer)";


ไม่มีปัญหาครับ ตอนนี้ปัญหาของผมน่าจะเกิดจากตอนรับค่าจาก contactForm.jsp มาที่ servletContact.java ครับ
ช่วยดูให้ทีครับ ผม request.getParameter("txtFormName").getBytes("ISO8859_1"),"UTF-8" ผิดรึป่าวครับ


ตัวอย่างโค้ดครับ

ContactForm.jsp
<%@ page contentType="text/html; charset=utf-8" %>
<% request.setCharacterEncoding("UTF-8"); %>
<!DOCTYPE HTML>
<html lang="th">
<head>
<meta charset='utf-8' />
<style>
	#contactTB{
		background:#daeaf3;
	}
</style>
</head>
<body>
<br>
<form action="./servletContact" method="get" name="regist">
		<table width="800" border="0" cellpadding="0" cellspacing="0" align="center">
			  <tr>
			    <td width="8" height="8" background="img/tb_lt.png"></td>
			    <td colspan="2" height="8" background="img/tb_t.png"></td>
			    <td width="8" height="8" background="img/tb_rt.png"></td>
			  </tr>
			  <tr>
			    <td background="img/tb_l.png"></td>
			    <td width="2"></td>
			    <td valign="top">
                	<div>
		                <table width="784" cellspacing="1" cellpadding="3" align="center" id="contactTB">
		                  	<tr>
		                  		<td colspan="2" align="center" background="img/headAddress.gif">ติดต่อสอบถามข้อมูล (Contact Information)</td>
		                  	</tr>
		                    <tr>
		                      <td align="right" valign="middle" style="font-size: 11px;" width="36%">ชื่อ-นามสกุล (Full Name) :</td>
		                      <td align="left"><input id="txtFormName" name="txtFormName" width="64%" size="30" type="text" maxlength="30"><font color="red">*</font></td>
		                    </tr>
		                    <tr>
		                      <td align="right" valign="middle" style="font-size: 11px;">ชื่อบริษัท (Company Name) :</td>
		                      <td align="left"><input id="txtFormCompany" name="txtFormCompany" size="30" type="text" maxlength="30"><font color="red">*</font></td>
		                    </tr>
		                    <tr>
		                      <td align="right" valign="middle" style="font-size: 11px;">ที่อยู่ (Address) :</td>
		                      <td align="left"><textarea name="txtFormAddress" cols="30" id="txtFormAddress"></textarea></td>
		                    </tr>
		                    <tr>
		                      <td align="right" valign="middle" style="font-size: 11px;">โทรศัพท์ (Telephone) :</td>
		                      <td align="left"><input id="txtFormTel" name="txtFormTel" size="30" type="text" maxlength="10"><font color="red">*</font></td>
		                    </tr>
		                    <tr>
		                      <td align="right" valign="middle" style="font-size: 11px;">แฟกซ์ (Fax) :</td>
		                      <td align="left"><input id="txtFormFax" name="txtFormFax" size="30" type="text" maxlength="10"></td>
		                    </tr>
		                    <tr>
		                      <td align="right" valign="middle" style="font-size: 11px;">อีเมล์ (Email) :</td>
		                      <td align="left"><input id="txtFormEmail" name="txtFormEmail" size="30" type="text" maxlength="30"><font color="red">*</font></td>
		                    </tr>
		                    <tr>
		                      <td align="right" valign="middle" style="font-size: 11px;">หัวข้อ (Subject) :</td>
		                      <td align="left"><input id="txtFormSubject" name="txtFormSubject" size="30" type="text" ><font color="red">*</font></td>
		                    </tr>
		                    <tr>
		                      <td align="right" valign="top" style="font-size: 11px; padding-bottom: 15px;">รายละเอียด (Message) :</td>
		                      <td align="left" style="padding-bottom: 5px;"><textarea name="txtFormMessage" cols="30" rows="5" id="txtFormMessage"></textarea><font color="red">*</font></td>
		                    </tr>
		                    <tr>
		                      <td colspan="2" align="center" style="padding-top: 5px;"><input type="submit" value="ส่งข้อความติดต่อสอบถาม"></td>
		                    </tr>
		                 </table>
                	</div>
                </td>
			    <td background="img/tb_r.png"></td>
			  </tr>			  
			  <tr>
			    <td width="8" height="8" background="img/tb_lb.png"></td>
			    <td colspan="2" height="8" background="img/tb_b.png"></td>
			    <td width="8" height="8" background="img/tb_rb.png"></td>
			  </tr>
			</table>
</form>
</body>
</html>



ไฟล์
servletContact.java
package contact;

import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import java.util.Date;
import java.text.SimpleDateFormat;


import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class servletContact
 */
@WebServlet("/servletContact")
public class servletContact extends HttpServlet {
	private static final long serialVersionUID = 1L;
	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		response.setContentType("text/html; charset=UTF-8");
		String fullName = new String(request.getParameter("txtFormName").getBytes("ISO8859_1"),"UTF-8");
		String nameCompany = new String(request.getParameter("txtFormCompany").getBytes("ISO8859_1"),"UTF-8");
		String address = new String(request.getParameter("txtFormAddress").getBytes("ISO8859_1"),"UTF-8");
		
		String tel = new String(request.getParameter("txtFormTel").getBytes("ISO8859_1"),"UTF-8");
		String fax =  new String(request.getParameter("txtFormFax").getBytes("ISO8859_1"),"UTF-8");
		String email = new String(request.getParameter("txtFormEmail").getBytes("ISO8859_1"),"UTF-8");
		String subject =  new String(request.getParameter("txtFormSubject").getBytes("ISO8859_1"),"UTF-8");
		String message =  new String(request.getParameter("txtFormMessage").getBytes("ISO8859_1"),"UTF-8");
		Date now = new Date();
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String datetime = df.format(now);
		
//		Sending Email.......................................................................
	    String textMessage = "มีการติดต่อสอบถามข้อมูลมายังบริษัทแอ๊กเซลเลนซ์สยาม (Have new contact to Excellence Siam.)\n"+
                                     "จาก : คุณ"+fullName+"\n"+
                                     "เรื่อง : "+subject+"\n"+
                                     "รายละเอียด : "+message+"\n"+
                                     "----------------- ข้อมูลลูกค้า ---------------------\n"+
                                     "ชื่อ-นามสกุล : "+fullName+"\n"+
                                     "บริษัท : "+nameCompany+"\n"+
                                     "ที่อยู่ : "+address+"\n"+
                                     "เบอร์โทรศัพท์ : "+tel+"\n"+
                                     "เบอร์แฟกซ์ : "+fax+"\n"+
                                     "อีเมลล์ : "+email ;
	    String textMessageCustomer = "ทางระบบได้รับข้อมูลการติดต่อจากคุณเรียบร้อยแล้ว กรุณารอติดต่อกลับจากบริษัท\nขอบคุณที่เลือกรับการบริการจากเราค่ะ";

	    String textSubject = "การติดต่อสอบถามข้อมูลจากลูกค้า (Contacted from customer)";
	    String textSubjectCustomer = "คุณได้ทำการติดต่อสอบถามข้อมูลจาก Excellence Saim Co., Ltd.";
		
		String host = "smtp.gmail.com";
		String port = "587";
		
		String user = "[email protected]";
		String pass = "excel0256";
		
		String recipient = "[email protected]";
		String recipient2 = "[email protected]";
		String recipientCC = "[email protected]";
				
		String resultMessage = "";
		String resultMessageBack = "";
		System.out.println(address);
		System.out.println(textMessage);
		try {
            EmailUtility.sendEmail(host, port, user, pass, recipient, recipient2, recipientCC, textSubject,
                    textMessage);
            EmailUtilityCustomer.sendEmail(host, port, user, pass, email, textSubjectCustomer, textMessageCustomer);
            
            resultMessage = "The e-mail was sent successfully";
            resultMessageBack ="The e-mail was sent to customer successfully";
        } catch (Exception ex) {
            ex.printStackTrace();
            resultMessage = "There were an error: " + ex.getMessage();
            resultMessageBack ="The e-mail was sent to customer error";
        } finally {
            System.out.println(resultMessage);
            System.out.println(resultMessageBack);
        }
				
		//Insert Database----------------------------------------------------------------------------------
		String sql = "INSERT INTO contact(name, name_company, address, tel, fax, email, subject, message, date_contact) " +
				"values ( '"+fullName+"', '"+nameCompany+"', '"+address+"', '"+tel+"', '"+fax+"', '"+email+"', '"+subject+"', '"+message+"', '"+datetime+"')";
		
		Connection con = null;
		PreparedStatement pst = null;
		
		try{
			con = DBConnect.getConnection();
			pst = con.prepareStatement(sql);
			pst.executeUpdate();
		}
		catch(SQLException e) {
			throw new ServletException(e);
		} 
		finally {
			if (pst != null) {
				try {
					pst.close();
				} catch (SQLException ignore) {
				}
			}
			if (con != null) {
				try {
					con.close();
				} catch (SQLException ignore) {
				}
			}
		}
		request.getRequestDispatcher("showAjax/contactFinish.jsp").forward(request, response);
	}
}




Tag : Java, JSP, Linux, Web Hosting









ประวัติการแก้ไข
2013-06-21 11:56:37
Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2013-06-21 11:55:03 By : lnwsit View : 12813 Reply : 2
 

 

No. 1

Guest


Code (Java)
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=UTF-8");

String fullName = request.getParameter("txtFormName");
String nameCompany = request.getParameter("txtFormCompany");
String address = request.getParameter("txtFormAddress");
 
String tel = request.getParameter("txtFormTel");
String fax =  request.getParameter("txtFormFax");
String email = request.getParameter("txtFormEmail");
String subject =  request.getParameter("txtFormSubject");
String message =  request.getParameter("txtFormMessage");







แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-06-21 16:38:14 By : ห้ามตอบเกินวันละ 2 กระทู้
 


 

No. 2

Guest



แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-07-14 01:35:52 By : Williams Carter
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : Java / JSP ช่วยที่ครับ มีปัญหา เกี่ยวกับภาษาไทย ในการส่งและรับค่า ตอนอัพขึ้น Hosting
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 05
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่