我使用Glassfish Netbeans IDE开发了一个小型Web应用程序。它适用于tomcat,但在Glassfish NetBeans中显示404错误。这是我的代码:
<h1> click one hyperlink </h1>
<a href="turl?p1=link1"> All Languages </a>
<br> <br> <br/>
<a href="turl?p1=link2"> All Countries </a>
<br><br><br/>
<a href="turl?p1=link3"> System Properties </a>
<br> <br> <br/>
的web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<servlet>
<servlet-name>abc</servlet-name>
<servlet-class>com.nt.TestSrv1</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>abc</servlet-name>
<url-pattern>/turl</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>page.html</welcome-file>
</welcome-file-list>
</web-app>
java代码
package com.nt;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.Locale;
public class TestSrv1 extends HttpServlet
{
protected void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException
{
//General Settings
PrintWriter pw=res.getWriter();
res.setContentType("text/html");
//read p1 req parameter values
String pval=req.getParameter("p1");
if(pval.equals("link1"))
{
Locale lcle[]=Locale.getAvailableLocales();
for(Locale lc:lcle)
{
pw.println("<br>"+lc.getDisplayLanguage());
}
}
else if(pval.equals("link2"))
{
Locale lcle[]=Locale.getAvailableLocales();
for(Locale lc:lcle)
{
pw.println("<br>"+lc.getDisplayCountry());
}
}
else
pw.println("System Properties: "+System.getProperties());
pw.close();
}
protected void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException
{
doGet(req,res);
}
}