Realize the first JSP and servlet

xiaoxiao2021-03-06  72

1. Download to the Sun Homepage Download the JDK installation version, assuming that the JDK is installed in C: /J2SDK1.4.2_03/, then set the environment variable java_home as C: /J2SDK1.4.2_03/, and then add C: / J2SDK1 in the environment Path variable. 4.2_03 / bin; add Tools.jar and Dt.jar in the ClassPath environment variable, if there is no ClassPath environment variable, create it. 2. Download the Tomcat installation version, assuming Tomcat is installed in c: /tomcat4.1; then set the environment variable Catalina_home is C: /Tomcat4.1; simultaneously add C: /Tomcat4.1/bin to the PATH environment variable. When you install Tomcat, you will be prompted to enter the password of Admin. This password is used to configure Tomcat. 3. Execute Catalina_Home / Bin / Startup.bat, launch Tomcat. Open the IE browser, type http: // localhost: 8080 / (guarantee port not to conflict with other server). "Tomcat Administration" appears on the left side of the page, "Tomcat Manager" two connections. 4. Create a web-inflicity under the C: / Establishing the Webroot directory, establish a web-infer in WebRoot, and establish a web.xml file in Web-INF. Edit Web.xml file, enter:

myfirstwebsite first Web then saved. 5. Click on "Tomcat Manager" to enter the username password (admin, admin) entered when installing. This is a graphical interface that manages Tomcat. 6. Open Catalina_Home / conf / server.xml, find , then add , Save, restart Tomcat, build an index.html under C: / Webroot, content yourself, then open IE, knock: http: // localhost: 8080 / Webroot / INDEX.html, you can browse The HTML file you just created just now. By this step, it basically established a separate site.

The following describes how to use JSP and servlets. 1. We build helloworld.jsp under C: / Webroot, enter the following: hello! </ Title> <meta name = "generator" content = "editplus"> <meta name = "Author" content = "> <meta name =" keywords "content ="> <meta name = "description" content = "> </ head> <body> <% out.println (" Hello World! " );%> </ Body> </ html> Save, then open the browser, knock: http: // localhost: 8080 / Webroot / HelloWorld.jsp, you can view the contents of JSP output.</p> <p>2. We created a servlet, named myServlet1.java, put under the C: / Webroot / SRC, the input content is as follows: import javax.servlet. *; Import javax.servlet.http. *; Import java.io. *; Import java.util. *;</p> <p>/ ** * <p> Title: </ p> * <p> Description: </ p> * <p> Copyright: Copyright (c) 2003 </ p> * <p> Company: </ p> * @ Author not attributable * @version 1.0 * /</p> <p>public class MyServlet1 extends HttpServlet {private static final String CONTENT_TYPE = "text / html; charset = GBK"; // Initialize global variables public void init () throws ServletException {} // Process the HTTP Get request public void doGet (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {response.setContentType (CONTENT_TYPE); PrintWriter out = response.getWriter (); out.println ( "<html>"); out.println ( "<head> <title> MyServlet1 </ title > </ head> "); out.println (" <body bgcolor = / "# fffffff /"> "); out.println (" <p> the servlet Has Received A Request.getMethod () ". This is the reply </ p> "); out.println (". </ body> </ html> ");} // Process the HTTP Post request public void doPost (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {Doget (Request, Response);} // clean up resources public void design () {}} 3. Open web.xml (where you know it), editing as follows: <? XML Version = "1.0" encoding = " ISO-8859-1 "?></p> <p><! Doctype web-app public "- // sun microsystems, incaps//dtd web application 2.3 // en" "http://java.sun.com/dtd/web-app_2_3.dtd"></p> <p><web-app> <display-name> MyfirstWebsite </ display-name> <description> first Web </ description></p> <p><servlet> <servlet-name> MyServlet1 </ servlet-name> <servlet-class> myservlet1 </ servlet-class> </ servlet> <servlet-maping> <servlet-name> MyServlet1 </ servlet-name> <URL -pattern> / myServlet1 </ url-pattern> </ servlet-mapping> </ web-app> saves.</p> <p>4. Compile Servlet: Create a lib directory in C: / Webroot / Web-INF / C: C: / Tomcat 4.1 / Common / lib / servlet.jar to the lib directory. Create a classes directory in C: / Webroot / Web-INF /. The Complier.bat content is built in C: / Webroot / below: javac -classpath ./web-inf/lib/servlet.jar; ./src/*.java -d ./web-inf/classespause runs company.bat Re-re- Start Tomcat, open the browser to knock http: // localhost: 8080 / Webroot / MyServlet1, execute, if it is the reply. "Indicates that the execution is successful.</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-92080.html</div><div class="plugin d-flex justify-content-center mt-3"></div><hr><div class="row"><div class="col-lg-12 text-muted mt-2"><i class="icon-tags mr-2"></i><span class="badge border border-secondary mr-2"><h2 class="h6 mb-0 small"><a class="text-secondary" href="tag-2.html">9cbs</a></h2></span></div></div></div></div><div class="card card-postlist border-white shadow"><div class="card-body"><div class="card-title"><div class="d-flex justify-content-between"><div><b>New Post</b>(<span class="posts">0</span>) </div><div></div></div></div><ul class="postlist list-unstyled"> </ul></div></div><div class="d-none threadlist"><input type="checkbox" name="modtid" value="92080" checked /></div></div></div></div></div><footer class="text-muted small bg-dark py-4 mt-3" id="footer"><div class="container"><div class="row"><div class="col">CopyRight © 2020 All Rights Reserved </div><div class="col text-right">Processed: <b>0.037</b>, SQL: <b>9</b></div></div></div></footer><script src="./lang/en-us/lang.js?2.2.0"></script><script src="view/js/jquery.min.js?2.2.0"></script><script src="view/js/popper.min.js?2.2.0"></script><script src="view/js/bootstrap.min.js?2.2.0"></script><script src="view/js/xiuno.js?2.2.0"></script><script src="view/js/bootstrap-plugin.js?2.2.0"></script><script src="view/js/async.min.js?2.2.0"></script><script src="view/js/form.js?2.2.0"></script><script> var debug = DEBUG = 0; var url_rewrite_on = 1; var url_path = './'; var forumarr = {"1":"Tech"}; var fid = 1; var uid = 0; var gid = 0; xn.options.water_image_url = 'view/img/water-small.png'; </script><script src="view/js/wellcms.js?2.2.0"></script><a class="scroll-to-top rounded" href="javascript:void(0);"><i class="icon-angle-up"></i></a><a class="scroll-to-bottom rounded" href="javascript:void(0);" style="display: inline;"><i class="icon-angle-down"></i></a></body></html><script> var forum_url = 'list-1.html'; var safe_token = 'p55bJu0D1zUEjMLg8mRKNNzy8_2FULGxg5V5D02w6qDtiblasWcJduKzmxA7uYXLSiDukltD1j3uURy4R9O2coYg_3D_3D'; var body = $('body'); body.on('submit', '#form', function() { var jthis = $(this); var jsubmit = jthis.find('#submit'); jthis.reset(); jsubmit.button('loading'); var postdata = jthis.serializeObject(); $.xpost(jthis.attr('action'), postdata, function(code, message) { if(code == 0) { location.reload(); } else { $.alert(message); jsubmit.button('reset'); } }); return false; }); function resize_image() { var jmessagelist = $('div.message'); var first_width = jmessagelist.width(); jmessagelist.each(function() { var jdiv = $(this); var maxwidth = jdiv.attr('isfirst') ? first_width : jdiv.width(); var jmessage_width = Math.min(jdiv.width(), maxwidth); jdiv.find('img, embed, iframe, video').each(function() { var jimg = $(this); var img_width = this.org_width; var img_height = this.org_height; if(!img_width) { var img_width = jimg.attr('width'); var img_height = jimg.attr('height'); this.org_width = img_width; this.org_height = img_height; } if(img_width > jmessage_width) { if(this.tagName == 'IMG') { jimg.width(jmessage_width); jimg.css('height', 'auto'); jimg.css('cursor', 'pointer'); jimg.on('click', function() { }); } else { jimg.width(jmessage_width); var height = (img_height / img_width) * jimg.width(); jimg.height(height); } } }); }); } function resize_table() { $('div.message').each(function() { var jdiv = $(this); jdiv.find('table').addClass('table').wrap('<div class="table-responsive"></div>'); }); } $(function() { resize_image(); resize_table(); $(window).on('resize', resize_image); }); var jmessage = $('#message'); jmessage.on('focus', function() {if(jmessage.t) { clearTimeout(jmessage.t); jmessage.t = null; } jmessage.css('height', '6rem'); }); jmessage.on('blur', function() {jmessage.t = setTimeout(function() { jmessage.css('height', '2.5rem');}, 1000); }); $('#nav li[data-active="fid-1"]').addClass('active'); </script>