java web服务器配置问题
来源:互联网 发布:网络新开游戏 编辑:程序博客网 时间:2024/06/15 23:51
- Servlet的时候eclipse已经帮助建好了url-patten。
- @WebServlet("/HelloWorld")
- public class HelloWorld extends HttpServlet {
- private static final long serialVersionUID = 1L;
- /**
- * @see HttpServlet#HttpServlet()
- */
- public HelloWorld() {
- super();
- // TODO Auto-generated constructor stub
- }
- /**
- * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
- */
- protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
- // TODO Auto-generated method stub
- doPost(request,response);
- }
- /**
- * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
- */
- protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
- // TODO Auto-generated method stub
- String u_name=request.getParameter("u_name");
- String ad="Welcome,"+u_name;
- request.setAttribute("ad", ad);
- request.getRequestDispatcher("/welcome.jsp").forward(request, response);
- }
- }
打开你的Servlet类,你会发现在类上面有一个@WebServlet("/HelloWorld")。
如果你在web.xml里面这样写:
<servlet>
<servlet-name>helloworld</servlet-name>
<servlet-class>HelloWorld</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>helloworld</servlet-name>
<url-pattern>/HelloWorld</url-pattern>
</servlet-mapping>
就是报错。
解决方法一:
去掉类上面的@WebServlet("/HelloWorld")。在web.xml写<servlet-mapping>。
解决方法二:
在web.xml里不写 <servlet-mapping>,而要保留@WebServlet("/HelloWorld")。如下web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
<display-name>HelloWorld</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>helloworld</servlet-name>
<servlet-class>HelloWorld</servlet-class>
</servlet>
</web-app>
进一步查看代码发现原来servlet类里面已经有一个:@WebServlet("/demo"),这好像是一个新特性,可以免去自己在web.xml中修改映射关系的过程,有可能是有重复定义的嫌疑,导致编译出错。
- java web服务器配置问题
- Java web 服务器配置
- lighttpd 配置 Java web服务器
- java web项目服务器配置
- eclipse中配置web服务器的问题。
- Linux下配置Java web服务器
- Linux服务器配置for java web
- 从零开始服务器配置java web项目
- 【JAVA WEB】TOMCAT服务器配置HTTPS
- JAVA 服务器 java home 配置的问题
- 阿里云https web服务器VPN的配置问题
- 阿里云Linux Ubuntu服务器上配置Java web项目过程(遇到的一些问题及要点)
- java web strusts2 配置中的问题
- web服务器安全配置
- web服务器配置笔记
- debian4r3 Web服务器配置
- WEB服务器配置
- WEB服务器的配置
- unity中用UGUI實現在UI界面鼠標旋轉三維物體
- 图片资源飘红
- java == 和equals的区别
- i3 Tiling Window Manager/ i3 平铺式窗口管理器
- 关于Android沉浸式状态栏字体颜色和图片背景自适应变化
- java web服务器配置问题
- Android程序的目录结构
- char和byte的区别
- 【codeforces B + 思维】
- Android开源的自定义dialog
- 相同的id 取一条记录 sql
- Zookeeper源码分析之一Server启动
- Java 8的新特性
- hanfulol123