您的位置:首页 > Web前端 > JavaScript

对jsp的一个小结(1)搭建web应用环境、用jsp实现输出、实现数据传递

2015-03-25 14:53 537 查看
</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"/>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: