码字基地
Eclipse学习基地
IT博客
首页
新随笔
联系
聚合
管理
2 Posts :: 0 Stories :: 0 Comments :: 0 Trackbacks
常用链接
我的随笔
我的评论
我参与的随笔
留言簿
给我留言
查看公开留言
查看私人留言
随笔档案
2010年1月 (2)
搜索
最新评论
阅读排行榜
1. (Web Pro 练习)页面跳转(165)
2. 安装Java编程环境(101)
评论排行榜
1. 安装Java编程环境(0)
2. (Web Pro 练习)页面跳转(0)
(Web Pro 练习)页面跳转
题目:
要求通过后台处理,从一个页面跳转到另一个页面。
目的:
学会如何部署动态web pro。
解答:
文件目录结构:
index.jsp
<%
@ page language
=
"
java
"
contentType
=
"
text/html; charset=ISO-8859-1
"
pageEncoding
=
"
ISO-8859-1
"
%>
<!
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=ISO-8859-1"
>
<
title
>
index
</
title
>
</
head
>
<
body
>
<
form
action
="welcome.do"
>
<
input
type
="submit"
value
="submit"
>
</
form
>
</
body
>
</
html
>
web.xml
<?
xml version="1.0" encoding="UTF-8"
?>
<
web-app
id
="WebApp_ID"
version
="2.4"
xmlns
="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi
="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation
="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
>
<
display-name
>
MyFirstWebPro
</
display-name
>
<
welcome-file-list
>
<
welcome-file
>
index.jsp
</
welcome-file
>
</
welcome-file-list
>
<
servlet
>
<
servlet-name
>
welcome
</
servlet-name
>
<
servlet-class
>
DoWelcome
</
servlet-class
>
</
servlet
>
<
servlet-mapping
>
<
servlet-name
>
welcome
</
servlet-name
>
<
url-pattern
>
/welcome.do
</
url-pattern
>
</
servlet-mapping
>
</
web-app
>
DoWelcome.java
import
java.io.IOException;
import
javax.servlet.ServletException;
import
javax.servlet.http.HttpServlet;
import
javax.servlet.http.HttpServletRequest;
import
javax.servlet.http.HttpServletResponse;
/** */
/**
* 控制页面跳转的Servlet。
*
*
@author
kocy
* 20100111
*/
public
class
DoWelcome
extends
HttpServlet
{
/** */
/**
* 跳转到welcome.jsp
*/
protected
void
service(HttpServletRequest requset, HttpServletResponse response)
throws
ServletException, IOException
{
response.sendRedirect(
"
/MyFirstWebPro/welcome.jsp
"
);
}
}
welcome.jsp
<%
@ page language
=
"
java
"
contentType
=
"
text/html; charset=ISO-8859-1
"
pageEncoding
=
"
ISO-8859-1
"
%>
<!
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=ISO-8859-1"
>
<
title
>
welcome
</
title
>
</
head
>
<
body
>
Welcome!
</
body
>
</
html
>
server.xml
.
<
Context
docBase
="MyFirstWebPro"
path
="/MyFirstWebPro"
reloadable
="true"
source
="org.eclipse.jst.j2ee.server:MyFirstWebPro"
/>
.
运行结果:
posted on 2010-01-11 23:15
天才码字员
阅读(165)
评论(0)
编辑
收藏
引用
Powered by:
IT博客
Copyright © 天才码字员