报错,不知道写的都是什么
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
Map<String,String> map=new HashMap();
PrintWriter out=response.getWriter();
map.put("apple","苹果");
map.put("banana","香蕉");
map.put("pig","猪");
String name=(String)request.getParameter("in1");
Iterator<String> it=map.values().iterator();
while(it.hasNext()){
if(it.next().equals(name)){
out.print(it.next());
}
}
</head>
<body>
<%
String name=request.getAttribute("name").toString();
%>
<h1 color:'blue'><%=name%></h1>
</body>
<body>
<form action='/Check/check'>
<input name='in1'><input type='submit'>
</form>
</body>
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8" isErrorPage="true"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Insert title here</title>
</head>
<body>
String msg=exception.getMessage();
out.print(msg);
</body>
</html>
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
<display-name>Check</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>
无法使用请检查
正在回答 回答被采纳积分+1
同学你好,代码实现有些许偏差,这里同学可以参考如下思路:
1、在Servlet中定义一个HashMap,存储中英文单词的信息,如apple为key值,苹果为value值,
2、然后对此进行判断,如果满足映射条件,就使用request的setAttribute() 方法来添加指定的属性,并为其赋指定的值。然后请求转发至success.jsp
3、反之给出错误信息提示,并重定向至fail.jsp页面

4、在success.jsp页面用getAttribute来返回指定属性名的属性值。如下所示:

5、fail.jsp页面同上所述

如果我的回答解决了你的疑惑,请采纳,祝学习愉快~
- 参与学习 人
- 提交作业 9410 份
- 解答问题 16556 个
综合就业常年第一,编程排行常年霸榜,无需脱产即可学习,北上广深月薪过万 无论你是未就业的学生还是想转行的在职人员,不需要基础,只要你有梦想,想高薪
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星