陈_C_C 2016-06-11 02:50 采纳率: 50%
浏览 1599
已采纳

eclipse+springmvc入门级项目myHelloWorld报404

helloWorld.jsp如下
<%@ page contentType="text/html; charset=GBK"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">


Spring输出HelloWorld

<%
String str=(String)request.getAttribute("helloWorld");
%>

size='22'<%=str%>>

dispatcherServlet-servlet如下
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"

"http://www.springframework.org/ dtd/spring-beans.dtd">

<!--定义映射-->
class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">


helloWorldController


<bean id="viewResolver" 

class="org.springframework.web.servlet.view.InternalResourceViewResolver">

org.springframework.web.servlet.view.InternalResourceView


<bean id="helloWorldController" class="com.myHelloWorld.action.HelloWorldController"> 
    <property name="helloWorld"> 
        <value>HelloWorld</value> 
    </property> 
    <property name="viewPage"> 
        <value>/jsp/helloWorld.jsp</value> 
    </property> 
</bean> 

web.xml如下
<?xml version="1.0" encoding="UTF-8"?>
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">

dispatcherServlet
org.springframework.web.servlet.DispatcherServlet
<!--初始化参数-->

contextConfigLocation
/WEB-INF/dispatcherServlet-servlet.xml


1

<servlet-mapping> 
     <servlet-name>dispatcherServlet</servlet-name> 
     <url-pattern>*.do</url-pattern> 
</servlet-mapping> 

HelloWorldController.java如下
//******* HelloWorldController.java**************

package com.myHelloWorld.action;

import java.io.IOException;

import java.util.HashMap;

import java.util.Map;

import javax.servlet.ServletException;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;

import org.springframework.web.servlet.mvc.Controller;

//实现了Controller接口

public class HelloWorldController implements Controller {

private String helloWorld;

private String viewPage;

//实现Controller接口中的handleRequest()方法

public ModelAndView handleRequest(HttpServletRequest req, HttpServletResponse res)

throws ServletException, IOException {

Map model = new HashMap();

model.put("helloWorld", getHelloWorld());

return new ModelAndView(getViewPage(), model);

}

//依赖注入要返回的页面

public void setViewPage(String viewPage) {

this.viewPage = viewPage;

}

//获取要返回的页面

public String getViewPage() {

return viewPage;

}

//依赖注入显示在页面中的文字

public void setHelloWorld(String helloWorld) {

this.helloWorld = helloWorld;

}

//获取要显示在页面中的文字

public String getHelloWorld() {

return helloWorld;

}

}

本地运行http://localhost:8080/myHelloWorld/helloWorld.do报如下错误:

HTTP Status 404 - /myHelloWorld/jsp/helloWorld.jsp

type Status report

message /myHelloWorld/jsp/helloWorld.jsp

description The requested resource is not available.

Apache Tomcat/7.0.55

  • 写回答

2条回答 默认 最新

  • lzj0327 2016-06-11 03:20
    关注
     helloWorld.do这个地址是怎么配上去的,没看出来
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 R语言爬虫的时候元素和园代码不一样怎么解决呀
  • ¥15 VS2022多项目启动有问题
  • ¥15 SQL删除添加数据后序号不连续问题。
  • ¥15 首次运行OmniEvent运行报错
  • ¥15 有没有人知道这个问题怎么解决
  • ¥15 comsol电力电缆载流量仿真
  • ¥15 webSocket可以接TCP socket接口吗
  • ¥60 mpi并行出错,CFD++计算
  • ¥15 c#:vsto,powerpoint的外接程序中换主题颜色
  • ¥15 状态机/汽车转向灯/Sateflow