Tamcat Learning 1 using MAVEN to create a new WebApp and read variable values from HelloServlet

Source: Internet
Author: User


1. In relation to the previous article, you need to create a new Helloservlet.java:

Package Org.ms.bop.server;import Java.io.ioexception;import Javax.servlet.servletexception;import Javax.servlet.http.httpservlet;import Javax.servlet.http.httpservletrequest;import javax.servlet.http.httpservletresponse;/** * Servlet Implementation class HelloServlet */public class HelloServlet    Extends HttpServlet {private static final long serialversionuid = 1L;      /** * Default constructor. */Public HelloServlet () {//TODO auto-generated constructor stub}/** * @see Httpservlet#doget (httpservletr Equest request, httpservletresponse response) */protected void doget (HttpServletRequest request, HttpServletResponse Response) throws Servletexception, IOException {request.setattribute ("Hello", "world1"); Request.getrequestdispatcher ("hello.jsp"). Forward (request, response);} /** * @see Httpservlet#dopost (httpservletrequest request, httpservletresponse response) */protected void DoPost ( HttpServletRequest request, HttpServletResponse response) throws Servletexception, Ioexception {//TODO auto-generated method stub}} 

2. New hello.jsp:

<%@ page language= "java" contenttype= "text/html; Charset=utf-8 "    pageencoding=" UTF-8 "%>    <%@ page iselignored=" false "%><! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" >

3. Configure Web. XML:

<! DOCTYPE Web-app Public "-//sun Microsystems, INC.//DTD Web Application 2.3//en" "Http://java.sun.com/dtd/web-app_2_3. DTD "><web-app><display-name>archetype Created Web application</display-name><servlet> <servlet-name>helloservlet</servlet-name><servlet-class>org.ms.bop.server.helloservlet</ Servlet-class></servlet><servlet-mapping><servlet-name>helloservlet</servlet-name> <url-pattern>/hello.do</url-pattern></servlet-mapping></web-app>

4. Publish Access:

Http://127.0.0.1:8080/WebTest/hello.do

The returned is:

Hello:world1

5. Summary of issues:

If the JSP does not add:

<%@ page iselignored= "false"%>


Will not recognize the EL, it shows:

Hello:${hello}






Tamcat Learning 1 using MAVEN to create a new WebApp and read variable values from HelloServlet

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.