This question already has answers here:
Difference between / and /* in servlet mapping url pattern
(5 answers)
Closed 2 years ago.
I am seeing 2 different URL pattern in web.xml. May I know what kind of URL matches with this pattern. It would be great if anyone explain this with example.
<filter-mapping>
<filter-name>samplewithstar</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>samplewithoutstar</filter-name>
<url-pattern>/</url-pattern>
</filter-mapping>
When you give /* it will select all the html tags.
Related
I am trying to find where the XSD and the semantics for the deployment descriptor web.xm file is defined in the Servlet 3.0 specification.
Alternatively, where is an authoritative description of the various supported elements and attributes that can appear inside web.xml and what the default behavior of the container is, in case some elements / attributes are absent.
This started by me wondering what is the default value for the http-only and secure elements inside session-config, e.g. as in:
<session-config>
<session-timeout>60</session-timeout>
<cookie-config>
<http-only>true</http-only>
<secure>false</secure>
</cookie-config>
</session-config>
I am reasonably certain the default values are false for both but I wanted to see where this is authoritatively specified.
Looking at the Java Servlet 3.0 spec there is no XSD. There is a sample XML file (on pg. 169) which has a schemaLocation attribute with value:
http://java.sun.com/xml/ns/j2ee/web-app_2_5.xsd
… which is broken. Googling for web-app_2_5.xsd an XSD file is found but it doesn't contain the definition of <session-config> element (I couldn't locate it even when googling for the other XSDs that that file imports).
The specification does contain graphical depictions of some elements (in the horrible late 90's style when such "visualizations" were in vogue) but this is all it contains for the session-config element:
There's no futher discussion for the cookie-config element.
I find it hard to believe that a specification does not contain the full XSD (or at least a link to it) and a detailed description of the semantics of all elements and attributes.
Am I missing something?
A list of schemas can be found at
http://www.oracle.com/webfolder/technetwork/jsc/xml/ns/javaee/index.html
(at the very beginning it is stated "Latest Version: http://xmlns.jcp.org/xml/ns/javaee/", which in turn redirects to the link I've posted first; I think the latter URL should be used as a permalink)
Then you'll find the schemas grouped by Java EE version. I think servlet 3.0 is JEE 6, so:
http://www.oracle.com/webfolder/technetwork/jsc/xml/ns/javaee/index.html#6
There you'll get the schemas:
http://www.oracle.com/webfolder/technetwork/jsc/xml/ns/javaee/web-app_3_0.xsd
http://www.oracle.com/webfolder/technetwork/jsc/xml/ns/javaee/web-common_3_0.xsd
http://www.oracle.com/webfolder/technetwork/jsc/xml/ns/javaee/web-fragment_3_0.xsd
Had problems with the schemas from oracle. The URLs were just not working, kept throwing an error.
so I switched to the jboss schema (at https://www.jboss.org/j2ee/schema/)
I replaced
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd
with
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee https://www.jboss.org/j2ee/schema/web-app_2_4.xsd"
Also make sure the version attribute on the web-app tag is set correctly (e.g. version="2.4" in this case)
Is there any difference between servlet-path and servlet-class tags when you define a servlet mapping under web.xml?
<servlet>
<servlet-name>register</servlet-name>
<servlet-path>box.RegisterServlet</servlet-path>
</servlet>
Say if were to change servlet-path to servlet-class would it make any difference?
If not,why are there 2 separate tags for doing the same thing?
Thanks!
There is no such attribute as <servlet-path/> in Servlet Spec. Only <servlet-class/> is allowed. Does it even work for you?
See also
web-app_2_5.xsd
web-app_3_0.xsd
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 11 years ago.
I am seeing a strange behavior in the data that is being inserted into the database. In the table say "table1" when I am inserting a record, for which one of the columns contains value as below:
?<?xml version="1.0" encoding="utf-8" ?>
- <OrderPayLoad xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<OrderID>182806333</OrderID>
<CreatedDateTime>2011-11-27T22:59:37.56</CreatedDateTime>
<MarketCode>XXX</MarketCode>
<AccountNumber>0</AccountNumber>
<MobileNumber>0</MobileNumber>
<OrderTotal>0</OrderTotal>
<OrderTaxTotal>0</OrderTaxTotal>
<PaymentMethod>NCC</PaymentMethod>
<ReceiptMethod>P</ReceiptMethod>
<ShippingInfo>
<FreightTypeID>1</FreightTypeID>
<ShippingAddressType>STANDARD</ShippingAddressType>
</ShippingInfo>
<BillingInfo>
<BillToZip>-</BillToZip>
</BillingInfo>
<OrderDetails />
<PaymentCard />
<OrderRoutingID>2</OrderRoutingID>
</OrderPayLoad>
Until the point I reach dbTransaction.Commit() I saw the above XML data in the column. When I check the database and pull up the same record, I see an extra character getting prefixed to the XML.
Any idea why this is occurring?
You have missed closing tag </OrderPayLoad>, so below is the correct xml, please use this:
<?xml version="1.0" encoding="utf-8" ?>
<OrderPayLoad xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<OrderID>182806333</OrderID>
<CreatedDateTime>2011-11-27T22:59:37.56</CreatedDateTime>
<MarketCode>XXX</MarketCode>
<AccountNumber>0</AccountNumber>
<MobileNumber>0</MobileNumber>
<OrderTotal>0</OrderTotal>
<OrderTaxTotal>0</OrderTaxTotal>
<PaymentMethod>NCC</PaymentMethod>
<ReceiptMethod>P</ReceiptMethod>
<ShippingInfo>
<FreightTypeID>1</FreightTypeID>
<ShippingAddressType>STANDARD</ShippingAddressType>
</ShippingInfo>
<BillingInfo>
<BillToZip></BillToZip>
</BillingInfo>
<OrderDetails />
<PaymentCard />
<OrderRoutingID>2</OrderRoutingID>
</OrderPayLoad>
What is the data type of your SQL column? The prefix char could be a the "BOM" (Byte-order-marker) used by UTF-8. If your column is text, char or varchar instead of ntext, nchar or nvarchar this could cause the extra symbol in front of your data.
This problem got fixed automatically, tried best to reproduce it. Not able to find the actual root cause.
How do I solve the
Reference to undeclared namespace prefix: '%s'
problem with Microsoft's msxml implementation?
I'm using an XML feed from a government web-site that contains values i need to parse. The xml contains namespaces:
<?xml version="1.0" encoding="ISO-8859-1"?>
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns="http://purl.org/rss/1.0/"
xmlns:cb="http://www.cbwiki.net/wiki/index.php/Specification_1.1"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:dcterms="http://purl.org/dc/terms/"
xmlns:xsi="http://www.w3c.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.w3c.org/1999/02/22-rdf-syntax-ns#rdf.xsd">
<item rdf:about="http://www.bankofcanada.ca/stats/rates_rss/STATIC_IEXE0101.xml">
<cb:statistics>
<cb:exchangeRate>
<cb:value decimals="4">1.0351</cb:value>
<cb:baseCurrency>CAD</cb:baseCurrency>
<cb:targetCurrency>USD</cb:targetCurrency>
<cb:rateType>Bank of Canada noon rate</cb:rateType>
<cb:observationPeriod frequency="daily">2011-05-09T12:15:00-04:00</cb:observationPeriod>
</cb:exchangeRate>
</cb:statistics>
</item>
</rdf:RDF>
Running the XPath query:
/rdf:RDF/item/cb:statistics/cb:exchangeRate/cb:targetCurrency
fails with the error:
Reference to undeclared namespace prefix: 'rdf'
Edit:
If i edit the original XML to remove all use of namespaces:
<?xml version="1.0" encoding="ISO-8859-1"?>
<rdf>
<item>
<statistics>
<exchangeRate>
<value decimals="4">1.0351</value>
<baseCurrency>CAD</baseCurrency>
<targetCurrency>USD</targetCurrency>
<rateType>Bank of Canada noon rate</rateType>
<observationPeriod frequency="daily">2011-05-09T12:15:00-04:00</observationPeriod>
</exchangeRate>
</statistics>
</item>
</rdf>
The query /rdf/item/statistics/exchangeRate/baseCurrency doesn't fail, and returns nodes:
<baseCurrency>CAD</baseCurrency>
How do i get Microsoft XML to work with namespaces?
Edit 2
i've tried adding SelectionNamespaces to the DOMDocument object:
doc.setProperty('SelectionNamespaces', 'xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:cb="http://www.cbwiki.net/wiki/index.php/Specification_1.1"');
Now the xpath query doesn't fail, but it also returns no nodes:
nodes = doc.selectNodes('/rdf:RDF/item/cb:statistics/cb:exchangeRate/cb:targetCurrency');
See also
“undeclared reference to namespace prefix ” error
XMLReader - How to handle undeclared namespace
PRB: Specifying Fully Qualified Element Names in XPath Queries
XPath not working properly.
Using SelectionNamespaces is the correct approach, you are just missing a namespace.
Notice that your XML document explicitly sets the default namespace as follows:
xmlns="http://purl.org/rss/1.0/"
This means that any element without a prefix, such as the item element, is actually in the default namespace. So if you want to select that element with an XPath expression, you must first set an appropriate selection namespace.
To do this, you can change your call to setProperty like so:
doc.setProperty('SelectionNamespaces', 'xmlns:rss="http://purl.org/rss/1.0/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:cb="http://www.cbwiki.net/wiki/index.php/Specification_1.1"');
Here you've assigned the default namespace from the document to the rss: prefix in your XPath expression. With that change in place, the following XPath expression should work correctly:
nodes = doc.selectNodes('/rdf:RDF/rss:item/cb:statistics/cb:exchangeRate/cb:targetCurrency');
It works because it references the item element using the correct namespace. The fact that the prefix differs between the XPath expression and the original document is immaterial. It is the namespace which the prefix is bound to that matters.
doc.setProperty('SelectionNamespaces', 'xmlns:rss="http://purl.org/rss/1.0/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:cb="http://www.cbwiki.net/wiki/index.php/Specification_1.1"');
Dont forget to load the xsd file or schema to the xmldoc object
is the way to go
I dont have enough reputation to comment. But that bit there saved me a lot of time.
Thank you so much
If you are using XMLSerializer and see this error, it is likely that you are running into the IE bug described here:
https://stackoverflow.com/a/11399681
It took me a lot of time to realize that this was happening, so I thought it best to link these two issues.
This question already has answers here:
ASP.NET MVC: Route with optional parameter, but if supplied, must match \d+
(6 answers)
Closed 9 years ago.
I want to use the url such as "/ControllerName/ActionName/Id"
Id - only digits or null.
But when I use regular expression in MapRoute, "\d{1,4}", I see the exception - error404 page, when I'm trying to see /ControllerName/ActionName/" page.
Also, I don't know, how I can catch exception with special symbol - ".
Please, help.Thanx.
Try using ( *|\d{1,4}).