完成三个jsp页面,要求如下:在login.jsp中,输入用户名和密码,提交到select.jsp页面,该页面有一个图书

选择下拉框,下拉框中包含三本书,分别为“Java Web应用开发基础”、“JSP程序设计”和“Java编程高手”。在下拉框中选择要购买的图书,提交到display.jsp页面,输出:“你好,xxx,你购买的图书是:yyy”,其中的xxx和yyy分别代表输入的用户名和选择购买的图书名。

第1个回答  2013-06-28

login.jsp页面:

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
   
    <title>My JSP 'index.jsp' starting page</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>
    <form action="select.jsp" method="post">
    <table width="300" align="center" border="0">
  <tr><td>账号:</td><td><input type="text" name="username" style="width:200"/></td></tr>
  <tr><td>密码:</td><td><input type="password" name="password" style="width:200"/></td></tr>
  <tr><td colspan="2" align="right"><input type="submit" value="登陆"/></td></tr>
  </table>
    </form>
  </body>
</html>

 

select.jsp页面:

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
   
    <title>My JSP 'index.jsp' starting page</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 username=request.getParameter("username");
  session.setAttribute("username",username); %>
    <form action="display.jsp" method="post">
    <table width="300" align="center" border="0">
  <tr><td>请选择书籍: </td><td><select name="book">
 <option value="1" selected>Java Web应用开发基础
 <option value="2">JSP程序设计
 <option value="3">Java编程高手
  </SELECT></td></tr>
  <tr><td colspan="2" align="right"><input type="submit" value="确定"/></td></tr>
  </table>
    </form>
  </body>
</html>

 

display.jsp页面

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
   
    <title>My JSP 'index.jsp' starting page</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 book="";
  if(request.getParameter("book").equals("1")){
  book="Java Web应用开发基础";
  }
  if(request.getParameter("book").equals("2")){
  book="JSP程序设计";
  }
  if(request.getParameter("book").equals("3")){
  book="Java编程高手";
  }
  %>
    您好!<font color="red"><%=session.getAttribute("username") %></font>,您购买的图书是:<%=book %>
  </body>
</html>

 

最后的效果图

追问

等会测试成功了,就给分,谢谢了!

追答

不懂再问,客气了

追问

朋友,能留下您的QQ吗?我还有些关于JSP的问题请教您,谢谢!

追答

Q407220738

本回答被提问者采纳
相似回答