JSP開發應用是
實例一
- <html>
- <head>
- <title>中文亂碼——JSP頁面顯示時</title>
- </head>
- <body>
- <center>
- <br/>
- <h
>木蘭辭擬古決絕詞柬友</h > - <p>人生若只如初見
何事秋風悲畫扇 </p> - <p>等閒變卻故人心
卻道故人心易變 </p> - <p>骊山語罷清宵半
淚雨霖鈴終不怨 </p> - <p>何如薄幸錦衣郎
比翼連枝當日願 </p> - </center>
- </body>
- </html>
運行結果
解決方法
- <%@ page contentType="text/html;charset=gb
" %>
實例二
注冊頁面
- <%@ page contentType="text/html;charset=gb
" %> - <html>
- <head>
- <title>中文亂碼——JSP頁面傳遞中文參數時</title>
- </head>
- <body>
- <h
>申請賬號 </h > - <form action="userMsg
jsp" method="POST"> - <p>郵箱
<input type="text"name="email" id="email"/><p/> - <p>昵稱
<input type="text"name="nickname" id="nickname"/><p/> - &n
bsp; <p>密碼
- <p>性別
<input type="radio"name="sex" id="sex"value="男" /> 男 - <input type="radio" name="sex"id="sex" value="女" /> 女<p/>
- <textarea name="introduction"id="introduction" rows="
" cols=" ">一句話介紹自己 </textarea> - <p><input type="submit"value="提交申請"></p>
- </form>
- </body>
- </html>
個人信息頁面
- <%@ page contentType="text/html;charset=gb
" %> - <html>
- <head>
- <title>中文亂碼——JSP頁面傳遞中文參數時 </title>
- </head>
- <body>
- <center>
- <h
>用戶信息 </h > - <% String email = request
getParameter("email"); %> - <% String nickname = request
getParameter("nickname"); %> - <% String password = request
getParameter("password"); %> - <% String sex = request
getParameter("sex"); %> - <% String introduction = request
getParameter("introduction");%> - <p>郵箱
<
;% out
- <p>昵稱
<% out print(nickname); %><p/> - <p>密碼
<% out print(password); %><p/> - <p>性別
<% out print(sex); %><p/> - <p>個人介紹
<%out print(introduction); %></p> - </center>
- </body>
- </html>
運行結果
解決方法
- <%@ page contentType="text/html;charset=gb
" %> - <html>
- <head>
- <title>中文亂碼——JSP頁面傳遞中文參數時 </title>
- </head>
- <body>
- <h
>用戶信息 </h > - <% String email = newString(request
getParameter("email") getBytes("ISO ") "gb ");%> - <% String nickname = newString(request
getParameter("nickname") getBytes("ISO ") "gb ");%> - <% String password = newString(request
getParameter("password") getBytes("ISO ") "gb ");%> - <% String sex = newString(request
getParameter("sex") getBytes("ISO ") "gb ");;%> - <% String introduction = newString(request
getParameter("introduction") getBytes("ISO ") "gb ");;%> - <p>郵箱
<% out print(email); %><p/> - &
lt;p>昵稱
- <p>密碼
<% out print(password); %><p/> - <p>性別
<% out print(sex); %><p/> - <p>個人介紹
<%out print(introduction); %></p> - </body>
- </html>
實例三
注冊頁面
- <%@ page contentType="text/html;charset=gb
" %> - <%@ page import="test
UserMsg"%> - <html>
- <head>
- <title>中文亂碼——JSP頁面傳遞中文參數時</title>
- </head>
- <body>
- <h
>申請賬號 </h > - <form action="
/UserMsg" method="POST"> - <p>郵箱
<input type="text"name="email" id="email"/><p/> - <p>昵稱
<input type="text"name="nickname" id="nickname"/><p/> - <p>密碼
<input type="password"name="password" id="password"/><p/> - <p>性別
<input type="radio"name="sex" id="sex"value="男" /> 男 - <input type="radio" name="sex"id="sex" value="女" /> 女<p/>
- <textarea name="introduction"id="introduction" rows="
" cols=" ">一句話介紹自己 </textarea> - <p><input type="submit"value="提交申請"></p>
- &nb
sp; </form>
- </body>
- </html>
UserMsg
- package test;
- importjava
io IOException; - importjava
io PrintWriter; - importjava
io UnsupportedEncodingException; - importjavax
servlet - importjavax
servlet - importjavax
servlet - public classUserMsg extends HttpServlet{
- public void doGet(HttpServletRequestrequest
- HttpServletResponse response){
- doPost(request
response); - }
- public void doPost(HttpServletRequestrequest
- HttpServletResponse response){
- try {
- request
setCharacterEncoding("gb "); - } catch (UnsupportedEncodingExceptione) {
- e
printStackTrace(); - }
- PrintWriter out = null;
- try {
- out = response
getWriter(); - } catch (IOException e
) { - e
printStackTrace(); - }
- out
print("<html>"); - &nbs
p; out
- out
print("<h >" +"用戶信息 "+ "</h >"); - out
print("<p>"+"郵箱 "+request getParameter("email")+"<p/>"); - out
print("<p>"+"昵稱 "+request getParameter("nickname")+"<p/>"); - out
print("<p>"+"密碼 "+request getParameter("password")+"<p/>"); - out
print("<p>"+"性別 "+request getParameter("sex")+"<p/>"); - out
print("<p>"+"個人介紹 "+request getParameter("introduction")+"<p/>"); - out
print("</html>"); - out
print("</body>"); - }
- }
運行結果
解決方法
- response
setContentType("text/html; charset=gb ");
From:http://tw.wingwit.com/Article/program/Java/JSP/201311/20624.html