新手学习mvc遇到的简单问题,请帮忙指教--在线等啊
1,model2hello.jsp
<%@ page contentType= "text/html;charset=GB2312 " %>
<%@ taglib prefix= "c " uri= "http://java.sun.com/jsp/jstl/core " %>
<html>
<head>
<title> CH18 - Model2Hello.jsp </title>
</head>
<body>
<h2> Model 2 范例 - Hello World </h2>
The Message is : <font color= "red "> ${requestScope.message} </font>
</body>
</html>
======================================================
2,model2hello.java
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class Model2Hello extends HttpServlet {
public void init(ServletConfig config) throws ServletException {
super.init(config);
}
public void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType( "text/html ");
String Message = "Hello World ";
String jsp = "/CH18/Model2Hello.jsp ";
request.setAttribute( "message ", Message);
RequestDispatcher rd = getServletContext().getRequestDispatcher(jsp);
rd.forward(request, response);
}
public void destroy() {
}
}
运行时遇到问题:
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: The absolute uri: http://java.sun.com/jsp/jstl/core cannot be resolved in either web.xml or the jar files deployed with this application
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:50)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:411)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:118)
org.apache.jasper.compiler.TagLibraryInfoImpl.generateTLDLocation(TagLibraryInfoImpl.java:316)
org.apache.jasper.compiler.TagLibraryInfoImpl. <init> (TagLibraryInfoImpl.java:147)
org.apache.jasper.compiler.Parser.parseTaglibDirective(Parser.java:418)
org.apache.jasper.compiler.Parser.parseDirective(Parser.java:483)
org.apache.jasper.compiler.Parser.parseElements(Parser.java:1539)
org.apache.jasper.compiler.Parser.parse(Parser.java:126)
org.apache.jasper.compiler.ParserController.doParse(ParserController.java:220)
org.apache.jasper.compiler.ParserController.parse(ParserController.java:101)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:203)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:470)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:451)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:439)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:511)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:295)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
note The full stack trace of the root cause is available in the Apache Tomcat/5.0.28 logs.
--------------------------------------------
Apache
[解决办法]
lz请看下面这句话:
The absolute uri: http://java.sun.com/jsp/jstl/core cannot be resolved in either web.xml or the jar files deployed with this application
确认你的jstl标签文件和jar包已经正确导入。
[解决办法]
把EL表达式换成百分号就好了
[解决办法]
<%@page contentType= "text/html "%>
<%@page pageEncoding= "gb2312 "%>
<html>
<head>
<title> CH18 - Model2Hello.jsp </title>
</head>
<body>
<h2> Model 2 范例 - Hello World </h2>
The Message is : <font color= "red "> ${requestScope.message} </font>
</body>
</html>
=========================================================================
楼主的JSP文件并没多大问题
<%@ taglib prefix= "c " uri= "http://java.sun.com/jsp/jstl/core " %>
这句话如果没导入文件确实会报那样的错误,
我在调试的时候没有导入那个文件也一样能运行。
=========================================================================
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class Model2hello extends HttpServlet
{
public void init(ServletConfig config) throws ServletException
{
super.init(config);
}
public void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
response.setContentType( "text/html ");
String Message = "Hello World ";
String jsp = "/model2hello.jsp ";
request.setAttribute( "message ", Message);
RequestDispatcher rd = getServletContext().getRequestDispatcher(jsp);
rd.forward(request, response);
}
public void destroy()
{
}
}
========================================================================
String jsp = "/model2hello.jsp "; 这里的路径前必须加 "/ " 由于已经在根目录下
所以不必再加上根项目
========================================================================
<?xml version= "1.0 " encoding= "UTF-8 "?>
<web-app version= "2.4 " xmlns= "http://java.sun.com/xml/ns/j2ee " xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance " xsi:schemaLocation= "http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd ">
<servlet>
<servlet-name> Model2hello </servlet-name>
<servlet-class> Model2hello </servlet-class>
</servlet>
<servlet-mapping>
<servlet-name> Model2hello </servlet-name>
<url-pattern> /Model2hello </url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>
model2hello.jsp
</welcome-file>
</welcome-file-list>
</web-app>
========================================================================
<url-pattern> /Model2hello </url-pattern> 之间的path是一个虚路径 不一定要写
CLASS文件的地址,只要你所访问的地址跟这个配置文件的虚路径的地址是一致的就行
了。好处就不用我说了吧
========================================================================
在webapps下面配置的时候 我是新建的项目文件mvc_test
必须要有的文件具体路径为:
D:\apache-tomcat-5.5.23\webapps\mvc_test\WEB-INF\classes\Model2hello.class
D:\apache-tomcat-5.5.23\webapps\mvc_test\WEB-INF\web.xml
D:\apache-tomcat-5.5.23\webapps\mvc_test\model2hello.jsp
=========================================================================
然后在地址栏输入:
http://localhost:8080/mvc_test/Model2hello
=========================================================================
[解决办法]
有否对.xml文件进行配置呢?
我的异常网推荐解决方案:The server encountered an internal error () that prevented it from fulfilling this request.,http://www.myexception.cn/java-web/317.html