jsp servlet 做一个简易计算
…………………………………………………………………
Jsp程序代码:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = ContextPath();
String basePath = Scheme()+"://"+ServerName()+":"+ServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>calculator</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">   
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->
  </head>
 
  <body>
 
  <%
    String first = (Attribute("first");
   
    String second = (Attribute("second");
   
    String operator = (Attribute("operator");
   
    String result = (Attribute("result");
   
   
 
  %>
 
  <h1>简易计算器</h1>
  <form method="post" action="CalculatorServlet">
      <input name="first" value="<%=(first==null?"":first) %>"/>
      <select name="operator" >
          <option  value="+">+</option>
          <option value="-">-</option>
          <option value="/">/</option>
          <option value="*">*</option>
          <option value="pow">square</option>
          <option value="sqrt">radication</option>
      </select>
    <input name="second" value="<%=(second==null?"":second) %>"/>  =<input name="result" value="<%=(result==null?"":result) %>" />
    <input value="计算" type="submit">
  </form>
  </body>
</html>
…………………………………………………………………
新建一个java beanjavaservlet和jsp的比较
程序如下:
package com.wp.bean;
public class Calculator

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。