您的位置:首页 > 移动开发

2014.08.19 周二-eclipse运行,快捷键-Mapping传参-web映射虚拟目录

2014-08-18 23:30 453 查看
师父越来越喜欢开玩笑了,不过遇到这么手把手带徒弟的师父,真的觉得好幸运(对我这种笨徒弟

)。开始熟悉项目了,师父让我看修改页面的数据是怎么传进去的,改了一下午,以为很快就能看到结果了。。。最终没运行出来(参数都没有传进去)。没有觉得技术这条路很枯燥

乐此不疲的对着电脑,敲着代码,激起了我无限的求知欲。爸妈老觉得我一天对着电脑的时间太长了,身体吃不消。。。碎碎念

一、commany遇到的问题

1、操作eclipse遇到的问题,快捷键

项目运行只能点第一个(因为每个都有关系,不过没搞懂这个关系),Console里面就会出现一个网址,在浏览器里面输入即可:


ctrl + shift + R(弹出搜索vm的框框)


ctrl + H(可以搜索在项目中出现的代码)



parent下面的修改无效,修改web下面那个
alt + ?(给出提示)
ctrl + shift + F(格式化代码格式)

2、Mapping小操作

testXin.java
@Controller
public class TestXin {
@RequestMapping("/xin/testXin.htm")
//这是映射的地址,虚拟的,实际不存在的,在浏览器中就输这个地址
public String queryFundsFreezeList(ModelMap modelMap, HttpServletRequest request) {
System.out.println("____________hehe—————————————————");
return "/depositBack/testXin.vm";  //这是实际存在的,在depositBack文件夹下
}
}

testXin.vm
<style type="text/css">.redAlert{color: red;margin-right: 3px}
</style>
#set ($JQ="$.")
#if($applicationConstant.getCurrentStoreFileType()==0)
#set ($webContextPath=$request.getContextPath()+"/")
#else
#set ($webContextPath="")
#end
<head>
#parse("layout/header.vm")
</head>
<body>
hello ,shifu!
</body>

<script>
seajs.use($_GLOBAL.mode + 'depositBack/addApplyDishonour.js');
</script>

显示结果:


3、传参数usernme

testXin.java
@Controller
public class TestXin {
@RequestMapping("/xin/testXin.htm")
public String queryFundsFreezeList(ModelMap modelMap, HttpServletRequest request) {
String username=request.getParameter("username");
modelMap.put("username", username);
return "/depositBack/testXin.vm";
}
}

test.vm(${username})
<style type="text/css">.redAlert{color: red;margin-right: 3px}
</style>
#set ($JQ="$.")
#if($applicationConstant.getCurrentStoreFileType()==0)
#set ($webContextPath=$request.getContextPath()+"/")
#else
#set ($webContextPath="")
#end
<head>
#parse("layout/header.vm")
</head>
<body>
hello , ${username} shifu!
</body>

<script>
seajs.use($_GLOBAL.mode + 'depositBack/addApplyDishonour.js');
</script>

显示结果(传入username=hahahaha,就把hahahaha传到${username}了):


4、小问题

登录网址,有时候输eclipse下面的网址显示不了登录界面。http://boss.yiji.dev:8123/auth/authPermission.htm
@RequestMapping(参数)(如果一个类下面有多个映射,就要用method之类的标识)
.vm文件可以用##注释(单行)

5、页面(修改过去修改过来的,脑壳都昏了)

最后以参数没有传进去而告终

二、巩固web

1、web应用和虚拟目录的映射

web应用程序指浏览器访问的程序,通常也简称为web应用
配置web应用供外部访问的过程叫虚拟目录映射
D:\web\fanglixun11day\day04\news下新建1.html
配置server.xml:(一个Context代表一个web应用)
<Context path="/news" docBase="D:\web\fanglixun11day\day04\news"/>
也可以这样写:
<Context path="/news" docBase="D:\web\fanglixun11day\day04\news"></Context>
/news是虚拟目录,在硬盘上是没有的;D:\web\fanglixun11day\day04\news是实际目录。改变server.xml之后要重启tomcat。通过http://localhost:8080/news/1.html访问。这种配置不好,因为程序上线了,不可能去重启服务器嘛
所以,在http://localhost:8080/中查询配置方法:
tomcat Documentation:配web应用(就是配Context)--> Reference:Configuration --> Containers:Context。有5种方式:
1:catalina_base/conf/context.xml(这种配置被所有web应用所共享,不建议);不知道怎么添加context?
2:被主机下的web应用共享。。。;
3:D:\apache-tomcat-7.0.54\conf\Catalina\localhost下新建a.xml:(就不用配path了,path就是a。不用重启服务器。通过http://localhost:8080/a/1.html访问)
<Context docBase="D:\web\fanglixun11day\day04\news"/>
把a.xml复制成b.xml也可以访问(http://localhost:8080/b/1.html),就是把同一个web应用映射到两个地址(一般采用第3种方式);把a.xml命名为a#b#c.xml,通过http://localhost:8080/a/b/c/1.html访问;
4:缺省的:把文件名a.xml命名为ROOT.xml(要重启服务器)http://localhost:8080/1.html(就不用指定a了);
<Context path="">就是缺省了
让tomcat服务器自动映射:webapps下建web应用(tomcat会自动管理webapps目录下的所有web应用,并把它映射成虚拟目录。即:tomcat服务器webapps目录中的web应用,外界可以直接访问)

2、web应用组织结构和web.xml文件的作用

每个web应用都有一个web.xml文件
web应用结构:
|--webapps
|--mail
|--1.html............. jsp, css, js文件等
|--WEB-INF
|--classes
|--1.class(java类)
|--lib(jar包)
|--web.xml
配置web.xml(抄头抄屁股)
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements.  See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License.  You may obtain a copy of the License at
 http://www.apache.org/licenses/LICENSE-2.0 
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<web-app 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_3_0.xsd" version="3.0">

<welcome-file-list>
<welcome-file>1.html</welcome-file>
</welcome-file-list>

</web-app>
显示1.html页面:

如果地址栏mail后面不输1.html,默认进入1.html(缺省的),因为<welcome-file>1.html</welcome-file>
server.xml:把mail配成缺省的
<Context path="" docBase="D:\apache-tomcat-7.0.54\webapps\mail"/>
通过http://localhost:8080/就可以访问mail下的1.html了
把8080改成80
web.xml必须放在WEB-INF目录中




内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: