JavaEE开发环境的配置运行

第一步:建立一个新的web project,名为openfund。

第二步:新建一个index.jsp页面。

<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%
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 'hello.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">

  </head>

  <body>
	<form name="index" action="second.jsp" method="get">
        <!-- <form name="index" action="fir1" method="get"> -->                                                                                                        <input type="text" name="username" value="roeshy" />                                                                                                      <input type="submit" value="submit" />                                                                                                               </form>                                                                                                                                             </body>                                                                                                                                                 </html>
 
第三步: 
新建一个second.jsp页面。 

<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%
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 'bbb.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">

  </head>
  
  <body>
    This is my JSP page. <br>
  </body>
</html>
第四步:创 建部署描述文件web.xml。
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
	http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
	<display-name></display-name>
	<servlet>
		<description>This is the description of my J2EE component</description>
		<display-name>This is the display name of my J2EE component</display-name>
		<servlet-name>first</servlet-name>
		<servlet-class>ecd.servlet.openfund.firstServlet</servlet-class>
	</servlet>

	<servlet-mapping>
		<servlet-name>first</servlet-name>
		<url-pattern>/fir1</url-pattern>
	</servlet-mapping>
	<welcome-file-list>
		<welcome-file>index.jsp</welcome-file>
	</welcome-file-list>
</web-app>
第五步:创 class firstServlet extends HttpServlet。servlet的访问路径通过<url-pattern>路径找到first,然后通过first找到ecd.servlet.openfund.firstServlet;fir1是页面表单提交的action的名称,暂时没用到。

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String name = request.getParameter(getServletName());
		response.sendRedirect("/openfund/index.jsp");
		//RequestDispatcher rd = request.getRequestDispatcher("/fir1");
		//rd.forward(request, response);
	}
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doGet(request, response);
	}
第六步:input http://localhost:8080/openfund/index.jsp

sendRedirect http://localhost:8080/openfund/bbb.jsp?username=roeshy

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值