對jsp的一個小結(1)搭建web應用環境、用jsp實現輸出、實現數據傳遞

</pre>1搭建web應用環境httplocalhost8080<p></p><p><span style="white-space:pre"></span>1.認識tomcat<span style="white-space:pre"> </span>2創建並運行web項目<span style="white-space:pre"> </span>3部署web項目</p><p>2.使用jsp實現輸出,3種註釋方式</p><p><span style="white-space:pre">1領取任務 2分析任務 3使用out.println輸出新聞標題</span>    4使用out.println輸出新聞內容     5使用=輸出新聞顯示頁面  6輸出新聞發表時間以及轉義字符  7jsp執行原理  8web程序調試和排錯</p><p></p><pre name="code" class="java"><body>
<!-- 全局變量和局部變量 -->
<% int i=10; %>
<%!int j=10; %>
<%!public void method1(){} %>
j++:<%=j++ %><br/>
i++:<%=i++ %>
</body>
<%
//post解決亂碼:設置請求的編碼方式
request.setCharacterEncoding("UTF-8");
//設置響應的編碼方式
//response.setCharacterEncoding("UTF-8");

String username=request.getParameter("username");
//String username=new String(t.getBytes("iso-8859-1"),"UTF-8");

if(username.equals("admin")){
	//不允許註冊,註冊失敗
	request.setAttribute("mess", "註冊失敗,請更換其他用戶名");
	request.getRequestDispatcher("userCreate.jsp").forward(request, response);
}else{
	//允許註冊,註冊成功
	request.setAttribute("mess", "註冊成功");
	response.sendRedirect("index.jsp");
}

out.print(username+"<br/>");
out.print(request.getParameter("password"));
out.print("<br/>");
String con_password=request.getParameter("con_password");
String email=request.getParameter("email");
%>


3實現數據傳遞

1.獲取表單提交的數據 

D:\jspworkspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\work\Catalina\localhost\LoginDemo\org\apache\jsp\jsp

2中文亂碼與頁面跳轉

	<%
	Object oMess=request.getAttribute("mess");
	if(oMess!=null)
		out.print(oMess.toString());
	%>

get解決亂碼:

<Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443" URIEncoding="UTF-8"/>



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章