老师麻烦看一下这个代码
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" import="cn.java.Servlet.*"%> <!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> <form action="http://localhost:8080/ServletADDcomputer/ADD"> <h3 align="center" >加法运算</h3> <p align="center">加数1:<input type="text" name="num1"></p> <p align="center">加数2:<input type="text" name="num2"></p> <p align="center"><input type="submit" value="计算"></p> </form> </body> </html>
package cn.java.Servlet; 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 Add extends HttpServlet{ /** * */ private static final long serialVersionUID = 1L; protected void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException{ String num1=request.getParameter("num1"); String num2=request.getParameter("num2"); int result=Integer.valueOf(num1)+Integer.valueOf(num2); response.setCharacterEncoding("UTF-8"); PrintWriter out=response.getWriter(); out.println("sum:"+result); } protected void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException{ doGet(request,response); } }
这是错误结果
16
收起
正在回答
2回答
点击计算以后也是没有问题的,建议同学贴一下web.xml里的代码,帮你看一下:
相似问题
登录后可查看更多问答,登录/注册
Java Web基础入门2018版
- 参与学习 716 人
- 提交作业 185 份
- 解答问题 1363 个
会Java?懂前端基础?想学后台开发?那么,赶快来学习《Java Web入门》路径吧。本路径主要介绍Java Web的基础知识,并配有大量案例,定会让你收获多多!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星