编写一个表单页面census.html,让用户填写姓名、性别(男女选择)、兴趣(运动,读书,音乐,书法及其他)

编写一个表单页面census.html,让用户填写姓名、性别(男女选择)、兴趣(运动,读书,音乐,书法及其他),第1张

表单:

<form action="doservlet" method="post">

姓名:<input name="user_name"><br>

性别<input type="radio" value="man" name="sex">男 <input type="radio" value="women" name="sex">女<Br />

爱好:<input type="check" name="likes" value="运动" />运动

<input type="check" name="likes" value="读书" />读书

<input type="check" name="likes" value="音乐" />音乐

<input type="check" name="likes" value="书法" />书法

</form>

servlet:

iimport java.io.IOException

import java.io.PrintWriter

import javax.servlet.ServletException

import javax.servlet.http.HttpServlet

import javax.servlet.http.HttpServletRequest

import javax.servlet.http.HttpServletResponse

public class doservlet extends HttpServlet {

/**

* Constructor of the object.

*/

public doservlet() {

super()

}

/**

* Destruction of the servlet. <br>

*/

public void destroy() {

super.destroy()// Just puts "destroy" string in log

// Put your code here

}

/**

* The doGet method of the servlet. <br>

*

* This method is called when a form has its tag value method equals to get.

*

* @param request the request send by the client to the server

* @param response the response send by the server to the client

* @throws ServletException if an error occurred

* @throws IOException if an error occurred

*/

public void doGet(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException {

response.setContentType("text/html")

PrintWriter out = response.getWriter()

out

.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">")

out.println("<HTML>")

out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>")

out.println(" <BODY>")

out.print("This is ")

out.print(this.getClass())

out.println(", using the GET method")

out.println(" </BODY>")

out.println("</HTML>")

out.flush()

out.close()

}

/**

* The doPost method of the servlet. <br>

*

* This method is called when a form has its tag value method equals to post.

*

* @param request the request send by the client to the server

* @param response the response send by the server to the client

* @throws ServletException if an error occurred

* @throws IOException if an error occurred

*/

public void doPost(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException {

response.setContentType("text/html")

PrintWriter out = response.getWriter()

String name = null

String sex = null

String likes[] = null

name=request.getParameter("user_name")

sex=request.getParameter("sex")

likes=request.getParameterValues("likes")

request.getSession().setAttribute("user_name", name)

request.getSession().setAttribute("sex", sex)

request.getSession().setAttribute("like",likes)

//把请求过来的数据放在session里

response.sendRedirect("目的页")

//在目的页中通过session的 getAttribute方法取出来即可

out.flush()

out.close()

}

/**

* Initialization of the servlet. <br>

*

* @throws ServletException if an error occure

*/

public void init() throws ServletException {

// Put your code here

}

}

你无须去记复杂的HTML语言,你可以用Netscape4.0或者WORD7.0,我用的是Frontpage.打开Netscape,在file菜单里选EditPage,便可以制作了.文字的处理基本跟Word没什么两样,关键是插入图片和产生链接.我们先做关于你自我介绍的一页,你先写上“大家好,我是superboy,下面是我的照片:”这时要放图片了,只须点击Insert菜单,选取Image,在Choosefile里选取你的图象文件即可,然后把这个文件保存为myself.html文件,放在myself的目录下。好,现在必须做封面了,你在封面写:“欢迎来到superboy的主页”以下是“自我介绍,我的爱好,我的工作”。你的自我介绍要链接到下一页去,你只须用鼠标选“自我介绍”后按鼠标右键,再选createlink,然后再选你myself目录下的myself.html,就将“自我介绍”链接到下一页了,以后在浏览器中一按,就可以跳到镶有你靓照的页面啦。在你的封面做好了所有链接和图片后,记住你必须将这一页保存为index.htm(有的主机要求必须为index.html),因为网页默认的主页名称是index.制作主页其实很简单,只要多实际制作,工多艺熟。还可以拿来主义,在网上看到什么好的主页,用另存为功能保存为.html格式的文件,细细研究人家是如何做的。还可以借用网页模版来搞,我的就是~~~~~~网页制作网址大全 http://www.soww.com/page/060.htm参考资料:http://xiaocun6589.go.nease.net/in/wangye%20zhizuo.htm参考资料:http://zhidao.baidu.com/question/5015128.html


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/8326548.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-15
下一篇 2023-04-15

发表评论

登录后才能评论

评论列表(0条)

保存