Java Web基础知识 2
Posted 曦~妍
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Java Web基础知识 2相关的知识,希望对你有一定的参考价值。
1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3 <%@ page import="java.util.*"%> 4 <%@ page import="java.sql.*" %> 5 <%@ page errorPage="errorpage.jsp" %> 6 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 7 <html> 8 <head> 9 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 10 <title>JSP首页</title> 11 </head> 12 <body> 13 这是JSP首页内容 14 <%="<br>输出" %> 15 <%="<br>这是Java字符串" %> 16 <%! 17 //!:全局变量(特殊的声明方式) 18 19 String str="<br>这是java变量"; 20 //访问计数器 21 int i=0; 22 int run() 23 { 24 return i++; 25 } 26 %> 27 <% 28 //java代码片段 29 /* 30 多行注释 31 */ 32 for(int m=0;m<10;m++) 33 {%> 34 35 <%="<br>"+m %> 36 <%} %> 37 <%=str%> 38 <br> i=<%= i++ %> 39 <br> i=<%=run() %> 40 41 %> 42 100+200的运算结果是<%=(100+200) %>,运算完成 43 <br> 44 <% 45 List<String> ls=new ArrayList<String>(); 46 ls.add("A"); 47 ls.add("B"); 48 ls.add("C"); 49 ls.add("D"); 50 for(String s:ls) 51 { 52 %> 53 <%=s %> 54 <%} %> 55 <!-- html注释 --> 56 <%--隐藏注释 --%> 57 <br> 58 <% int k=0; 59 String path="inc/testinc2.jsp"; 60 %> 61 <%@ include file="inc/testinc.jsp"%> 62 <jsp:include page="<%=path %>"> 63 <jsp:param value="tom" name="user"/> 64 </jsp:include> 65 66 <br>动作标识 67 <br>包含文件2 68 <!--<jsp:include page="inc/testinc2.jsp"></jsp:include> 69 <jsp:param value="tom" name="user"/> 70 <jsp:forward page="Errorpage.jsp"></jsp:forward>--> 71 72 <jsp:forward page="test1.jsp"> 73 <jsp:param value="tom1" name="name"/> 74 <jsp:param value="123456" name="password"/> 75 </jsp:forward> 76 </body> 77 </html>
1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3 4 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 5 <html> 6 <head> 7 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 8 <title>Insert title here</title> 9 </head> 10 <body> 11 <% 12 //System.out.print("向控制台输入信息"); 13 14 String name=request.getParameter("name"); 15 String password=request.getParameter("password"); 16 out.print("<br>接收的参数name为:"+name); 17 out.print("<br>接受的参数password为:"+password+"<br>"); 18 //内置对象 19 out.print("向浏览器输入信息"); 20 String str="信息"; 21 out.println(str); 22 out.println(str); 23 for(int i=0;i<10;i++) 24 { 25 out.println("<br> i="+i); 26 } 27 %> 28 </body> 29 </html>
1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 4 <html> 5 <head> 6 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 7 <title>Insert title here</title> 8 </head> 9 <body> 10 11 <form action="test1.jsp" method="post"> 12 名称:<input type="text" name="name" 13 <br><br><br> 14 密码:<input type="password" name="password"> 15 <br><br> 16 <input type="submit" value="提交"> 17 </form> 18 </body> 19 </html>
1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 4 <html> 5 <head> 6 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 7 <title>Insert title here</title> 8 </head> 9 <body> 10 11 <form action="test1.jsp" > 12 名称:<input type="text" name="name" 13 <br><br><br> 14 密码:<input type="password" name="password"> 15 <br><br> 16 <input type="submit" value="提交"> 17 </form> 18 </body> 19 </html>
以上是关于Java Web基础知识 2的主要内容,如果未能解决你的问题,请参考以下文章
[原创]java WEB学习笔记61:Struts2学习之路--通用标签 property,uri,param,set,push,if-else,itertor,sort,date,a标签等(代码片段