Java 执行servlet程序时出错
在练习servlet程序时,我遇到了这个问题。现在我在我创建的任何项目中都面临着同样的问题。不知道我做错了什么。我正在使用netbeans 8.1和glass fish服务器。错误是:-Java 执行servlet程序时出错,java,servlets,netbeans,glassfish,netbeans-8.1,Java,Servlets,Netbeans,Glassfish,Netbeans 8.1,在练习servlet程序时,我遇到了这个问题。现在我在我创建的任何项目中都面临着同样的问题。不知道我做错了什么。我正在使用netbeans 8.1和glass fish服务器。错误是:- HTTP Status 500 - Internal Server Error type Exception report messageInternal Server Error descriptionThe server encountered an internal error that prevente
HTTP Status 500 - Internal Server Error
type Exception report
messageInternal Server Error
descriptionThe server encountered an internal error that prevented it from
fulfilling this request.
exception javax.servlet.ServletException: Error instantiating servlet class calc
root cause
com.sun.enterprise.container.common.spi.util.InjectionException: Error creating managed object for class: class calc
root cause
java.lang.NoSuchMethodException: calc.<init>()
note The full stack traces of the exception and its root causes are available in the
GlassFish Server Open Source Edition 4.1 logs.
GlassFish Server Open Source Edition 4.1
xml代码:-
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
<servlet>
<servlet-name>calc</servlet-name>
<servlet-class>calc</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>calc</servlet-name>
<url-pattern>/calc</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>
计算
计算
计算
/计算
30
index.html
您的serlvet类必须扩展javax.servlet.http.HttpServlet类
public class calc extends the javax.servlet.http.HttpServlet
{
public void doGet(HttpServletRequest req,HttpServletResponse res) throws IOException,ServletException
{
.....
对于第二个错误,我不确定为什么会出现此错误,可能是inject对象的另一个配置,但要解决此问题,必须创建一个没有参数的公共构造函数
public class calc extends the javax.servlet.http.HttpServlet
{
public calc() {}
public void doGet(HttpServletRequest req,HttpServletResponse res) throws IOException,ServletException
{
.....
你想点击的网址是什么?对于index.html,它与参数一起完美运行,参数根据action=“”进入servlet是愚蠢的错误。我纠正了它,但现在它是一个完全不同的错误。我更新了post@augustushill你能把错误日志部分贴在日志部分吗?我是这个网站的新手,这是某种错误发布约定吗?只需复制并通过glassfish日志中的文本,您会发现java.lang.NoSuchMethodException问题。没有为类指定访问说明符。这是个错误。谢谢。:)
public class calc extends the javax.servlet.http.HttpServlet
{
public void doGet(HttpServletRequest req,HttpServletResponse res) throws IOException,ServletException
{
.....
public class calc extends the javax.servlet.http.HttpServlet
{
public calc() {}
public void doGet(HttpServletRequest req,HttpServletResponse res) throws IOException,ServletException
{
.....