java.web(html与jsp)(2)

1.要求:

通过HTML表单输入一个4个选项的复选框字段,提交给jsp程序,要求在浏览器上输出这4个复选框哪几个被勾选了。
1)HTML程序如下:

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>爱好</title>
</head>
<body>
<form action="strchallenge1.jsp" method="post">
<h1>请选择你的爱好</h1>
<br>
<ol >
<li><p >打篮球<input type=checkbox value="true" name="one"></p></li>
<li><p >听音乐、唱歌<input type=checkbox value="true" name="two"></p></li>
<li><p >看电影<input type=checkbox value="true" name="three"></p></li>
<li><p >打羽毛球<input type=checkbox value="true" name="four"></p></li>
</ol>
<p ><input type="submit" value="提交"></p>
</form>
</body>
</html>

2)jsp程序如下:

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>结果</title>
</head>
<body>
<h1 align="center">结果</h1>
<%
String [] one =request.getParameterValues("one");
String [] two=request.getParameterValues("two");
String [] three=request.getParameterValues("three");
String [] four=request.getParameterValues("four");
%>
<h4 align="center"><%
if(one!=null&&two!=null&&three!=null&&four!=null){
	out.print("你选了1、2、3、4");
}
else if(one!=null&&two!=null&&three!=null){
	out.print("你选了1、2、3");
}
else if(two!=null&&three!=null&&four!=null){
	out.print("你选了2、3、4");
}
else if(one!=null&&three!=null&&four!=null){
	out.print("你选了1、3、4");
}else if(one!=null&&two!=null&&four!=null){
	out.print("你选了1、2、4");
}else if(one!=null&&two!=null){
	out.print("你选了1、2");
}else if(one!=null&&three!=null){
	out.print("你选了1、3");
}else if(one!=null&&four!=null){
	out.print("你选了1、4");
}else if(two!=null&&three!=null){
	out.print("你选了2、3");
}else if(two!=null&&four!=null){
	out.print("你选了2、4");
}else if(one!=null){
	out.print("你选了1");
}else if(two!=null){
	out.print("你选了2");
}
else if(three!=null){
	out.print("你选了3");
}
else if(four!=null){
	out.print("你选了4");
}else{
	out.print("你什么都没选");
}

%></h4>
<a href="strchallenge1.html">返回上一级</a>

</body>
</html>

运行结果:
在这里插入图片描述

2.要求:

通过HTML表单输入一个字符串,提交给jsp程序,要求输入的字符串被原模原样输入到浏览器。
例如:输入字符串:abcde 在浏览器上输出为:abcde。
例如:输入字符串:数学<font color=’#ff0000’>100</font>分 在浏览器上输出为:数学<font color=’#ff0000’>100</font>分而不是输出:数学100分。
1)HTML程序如下:

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>字符串输出</title>
</head>
<body>
<form action="strchallenge2.jsp" method="post">
<h1 align="center">字符串输出</h1>
<p align="center">字符串:<input type="text" name="str1" placeholder="请输入一个字符串"></p>
<p align="center"><input type="submit" value="提交"></p>
</form>
</body>
</html>

2)jsp程序如下:

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>字符串输出</title>
</head>
<body>

<%
request.setCharacterEncoding("UTF-8");
String str1=request.getParameter("str1");

%>
<h4 align="center"><p ><xmp><% out.print("你输入的字符串是:"+str1);%></xmp></P></h4>>
<a href=strchallenge2.html>返回上一级</a>
</body>
</html>

运行结果:
在这里插入图片描述

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值