在目录下添加名为hello.jsp的文件html
代码就是很简单的输出helloworld浏览器
1: <html>2: <head>3: <title>JavaWeb学习</title>4: </head>5: <body>6: <%
7: out.print("<h1>Hello World!!!</h1>");8: %>9: </body>10: </html>11:
将程序保存在虚拟目录下,并经过浏览器输入地址jsp
http://localhost/gb//hello.jsppost
运行结果以下学习
能够发现,该JSP程序主要仍是由HTML代码组成的。ui
因此,所得的JSP程序代码开发就是指在HTML中嵌入大量的Java代码spa
例4.4.net
编写表单,输入内容——input.htmcode
具体代码以下orm
1: <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />2: <html>3: <head>4: <title>Java学习</title>5: </head>6: <body>7: <center>8: <form action="input.jsp" method="post">9: 请输入要显示的内容:<input type="text" name="info" >10: <input type="submit" value="显示" />11: </form>12: </center>13: </body>14: </html>
运行结果以下
例4.5
接收输入表单参数并显示——input.jsp
1:2: <html>3: <head>4: <title>JavaWeb学习</title>5: </head>6: <body>7: <%8: String str=request.getParameter("info"); //接收表单输入的内容9: out.print("<h1>"+str+"</h1>"); //输入信息10: %>11: </body>12: </html>
运行结果以下
表单提交后,会将表单中的内容提交给action所指向的路径,而input.jsp将直接输出表单的输入内容。