<!-- language: java--> package bhatti; public class find extends HttpServlet { @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;"); PrintWriter out = response.getWriter(); out.println("<html><body>"); out.println("<feildset>"); out.println("<form action='display' method='get'>"); out.println("<tr>"); out.println("<td>ID :</td><td> <input type='text' name='id' style='width=70px;'></td><tr><br>"); out.println("<tr><td>Uints: </tr><tr><input type='text' name='uints' style='width=70px;' ></td></tr><br>"); out.println("<tr><td><input type='submit' value='submit' ></td></tr><br>"); out.println("</form>"); out.println("</feildset>"); out.println("</body></html>"); int i = Integer.parseInt(request.getParameter("id")); int u = Integer.parseInt(request.getParameter("uints")); float bill; bill = (float)(u * (1.5)); float s; s = (float)(bill * 0.05); float totalbill; totalbill = bill - s; RequestDispatcher requestDispatcher = getServletContext().getRequestDispatcher("display.java"); requestDispatcher.forward(request, response); request.setAttribute("id", i); request.setAttribute("uints", u); request.setAttribute("totalbill", totalbill); } }second servletpackage bhatti;import java.io.IOException;import java.io.PrintWriter;import javax.servlet.ServletException;import javax.servlet.annotation.WebServlet;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import javax.servlet.http.HttpSession; }}浮点值未发送到其他 servlet错误是 HTTP 状态 500 -类型异常报告信息描述 服务器遇到内部错误,无法满足此请求。note Apache Tomcat/8.0.27 日志中提供了根本原因的完整堆栈跟踪。
1 回答
元芳怎么了
TA贡献1798条经验 获得超7个赞
您正在一个 servlet 中设置属性,并尝试在另一个 servlet 中获取参数。
setAttribute值不能通过getParameter获取,
setAttribute值只能通过getAttribute获取
因此,使用请求中的 getAttribute 作为
request.getAttribute ("totalBill") ;
在您的情况下,request.getParameter("totalBill")
为 NULL 并且Float.parseFloat(null)
将通过NullPointerException
,因此您得到 HttpResponse 状态 500,即内部服务器错误。
添加回答
举报
0/150
提交
取消