按照老师来的操作还是报错我已经无奈了
package com.imooc.seervlet;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class FirstServlet extends HttpServlet{
@Override
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String name = request.getParameter("name");
String html = "<h1 style='color:blue'>"+ name +"</h1>";
PrintWriter out = response.getWriter();
System.out.println("返回给浏览器的响应数据为 :"+html);
out.println(html); //将html发送回浏览器
}
}
html代码
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>学员信息登记表</title>
</head>
<body>
<h1 >学员信息登记表</h1>
<form action="http://localhost:8080/FirstServlet/sample">
姓名: <input name ="name"/>
<br/>
电话: <input name = "mobile"/>
<br/>
性别:
<select name="sex" style="width:100px;padding:5px;">
<option value="male">男</option>
<option value="female">女</option>
</select>
<br/>
特长:
<input type="checkbox" name="spec" value="EngLish"/>英语
<input type="checkbox" name="spec" value="Program"/>编程
<input type="checkbox" name="spec" value="Speech"/>演讲
<input type="checkbox" name= "spec" value="Swimming"/>游泳
<br/>
<input type="submit" value="提交">
<br/>
</form>
</body>
</html>
xml代码
<?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>FirstServlet</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>
<!-- 声明Servlet -->
<servlet>
<!-- servlet的别名 -->
<servlet-name>second</servlet-name>
<servlet-class>com.imooc.seervlet.thesecondServlet</servlet-class>
</servlet>
<!-- 将Servlet与URL绑定 -->
<servlet-mapping>
<servlet-name>second</servlet-name>
<url-pattern>/ShopServlet</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>sample</servlet-name>
<servlet-class>com.imooc.seervlet.FirstServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>sample</servlet-name>
<url-pattern>/sample</url-pattern>
</servlet-mapping>
<!-- 将Servlet与URL绑定 -->
<servlet>
<servlet-name>sum</servlet-name>
<servlet-class>com.imooc.seervlet.ServletSum</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>sum</servlet-name>
<url-pattern>/number</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>sample</servlet-name>
<servlet-class>com.imooc.servlet.student</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>sample</servlet-name>
<url-pattern>/sample</url-pattern>
</servlet-mapping>
</web-app>
老师能够帮我分析下哪里错了吗我实在是找不出来了!!!!
正在回答 回答被采纳积分+1
- 参与学习 人
- 提交作业 1088 份
- 解答问题 10205 个
如果你有Java语言基础,又想以后从事Java Web开发,那么本路径是你的不二选择!本路径从网页搭建开始入手,通过大量案例来学习Java Web基础。定能助你完成Java Web小白的蜕变!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星