JSP gets the parameters defined in the Web.xml

Source: Internet
Author: User
Tags object config
Js|web|xml set the parameters in the Web.xml file:
<?xml version= "1.0" encoding= "Iso-8859-1"?>
<! 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>



<servlet>
<servlet-name> myjsp </servlet-name>
<jsp-file>/myjsp.jsp </jsp-file>
<init-param>
<param-name>firstparam</param-name>
<param-value>firstparamvalue</param-value>
</init-param>
</servlet>



<servlet-mapping>
<servlet-name> myjsp </servlet-name>
<url-pattern>/myurl/* </url-pattern>
</servlet-mapping>



</web-app>



The following program cannot take out the value of the parameter Firstparam defined in Web.xml firstparamvalue
My init parameter is <%= application.getinitparameter ("Firstparam")%>



The following program can take out the value of the parameter Firstparam defined in Web.xml firstparamvalue
<%
String Str1;
Str1=config.getinitparameter ("Firstparam");
Out.println (STR1);
%>



Because config is an object of class Javax.servlet.ServletConfig, application is an object of class Javax.servlet.ServletContext.
If you specify that the listening port for WebLogic server is 80, you do not need to enter the port in IE
Http://hostname/myfile.html replaces http://hostname:portnumber/myfile.html.


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.