对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"/>



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值