由于我的原因,项目主页的网址因未知而更改。两天前它是: http:// localhost:8080 / simpleblog / 现在它是 http:// localhost:8080 / mvc3 / 。这是在我尝试将一些视图添加到家庭控制器之后发生的,但我没有更改控制器的映射,只更改了视图。
家庭控制器正在寻找以下方式:
@Controller
public class HomeController {
@PersistenceContext
private EntityManager entityManager;
private static final Logger logger = LoggerFactory.getLogger(HomeController.class);
/**
* Simply selects the home view to render by returning its name.
*/
@RequestMapping(value = "/", method = RequestMethod.GET)
public ModelAndView home(Locale locale, Model model)
{
logger.info("Welcome home! the client locale is "+ locale.toString());
logger.info("Running SIMPLE_BLOG");
Date date = new Date();
DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);
String formattedDate = dateFormat.format(date);
model.addAttribute("serverTime", formattedDate );
// Check for compatibility
List listTopic = entityManager.createQuery("select o from Topic o").getResultList(); // delete the last 'o' if an error occurs
//model.addAttribute("Topics", listTopic);
return new ModelAndView("home", "model", listTopic);
}
@RequestMapping(value = "/create", method = RequestMethod.GET)
public ModelAndView Create(Locale locale, Model model)
{
Topic newTopic = new Topic();
logger.info("HomeControlller: Create");
List<Tag> tagList = newTopic.getTagLict();
Hashtable modelData = new Hashtable();
modelData.put("topic", newTopic);
modelData.put("tagList", tagList);
return new ModelAndView("create", modelData);
}
@RequestMapping(value = "/details/(topicId)")
public ModelAndView Details(@PathVariable(value="topicId") int id)
{
Topic topicById = (Topic) entityManager.createQuery("select o from Topic o where o.id =: myId")
.setParameter("myId", id)
.getSingleResult();
return new ModelAndView("/topic/", "model", topicById);
}
}
请告诉我,我应该修复什么来返回项目的以前的网址
UPD 在我的 servlet-context.xml 中,我有以下几行:
...
<context:component-scan base-package="com.epam.mvc3.model" />
<context:component-scan base-package="com.epam.mvc3.controller" />
...
我找不到另一个明确的引用mvc3
UPD-2 在我的server.xml中,我可以看到以下内容:
<Host appBase="webapps" autoDeploy="true" deployOnStartup="true" deployXML="true" name="localhost" unpackWARs="true">
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" pattern="%h %l %u %t "%r" %s %b" prefix="localhost_access_log." suffix=".txt"/>
<Context docBase="SimpleBlog" path="/mvc3" reloadable="true" source="org.eclipse.jst.jee.server:SimpleBlog"/>
</Host>
主机标签是否会影响项目主页的URL?
答案 0 :(得分:0)
您的 server.xml 文件必须已更改,特别是路径。
关于你的更新,你的server.xml指定它:
<Context docBase="SimpleBlog" path="/mvc3" reloadable="true" source="org.eclipse.jst.jee.server:SimpleBlog"/>
改变你想要的路径,这就是我的压力:
<Context docBase="SimpleBlog" path="/SimpleBlog" reloadable="true" source="org.eclipse.jst.jee.server:SimpleBlog"/>
答案 1 :(得分:0)
Web应用程序的基本URL通常由默认的Web应用程序名称确定,该名称通常是WAR文件的基本名称。你重命名了你的WAR文件吗?
另一种可能性是您在servlet或容器配置中明确设置名称;例如server.xml
文件或context.xml
文件或类似内容。