Struts return JSP style is missing the style path is not correct

Source: Internet
Author: User

When you jump to the JSP display after using the Struts2 action, the CSS does not work, take the project that I'm having a problem with, for example:

The action is as follows:

<action name= "Listuser" class= "Listuseraction" >
<result>/users/userList.jsp</result>
</action>

(Note: Listuser's role is to find out all the users, and then to users under the userlist.jsp display.) Because spring is used, the "listuseraction" here is the name configured in Applicationcontext.xml)

The CSS settings in userlist.jsp are as follows:
<link href= ". /css/style.css "rel=" stylesheet "type=" Text/css "/>

(Note: directory hierarchy is like this, Webroot under the Users and CSS folders, so users under the JSP to call STYLE.CSS need: /To the root directory, and then find the CSS folder)

However, when the program from the successful execution of Listuser jump to/users/userlist.jsp when the/CSS/STYLE.CSS does not work, if directly in the address bar directly display JSP and can display correctly.

Methods found on the internet say CSS with absolute path:

<link href= "<%=rootpath%>/css/style.css" rel= "stylesheet" type= "Text/css"/>

But there is a very obvious drawback, that is, the transplant of poor.

Try to change the result to <result>userlist.jsp</result>, and then put the JSP in the root directory there is no such problem, this time the cause of the problem is pretty much know, that is the action is in the root directory, When running the program from the address bar can be seen, that is, the namespace is in the root directory, this time again ". /css/style.css "Nature will not find it.

Understand the problem, the solution is not difficult to find. Find Listuser's configuration in the package, plus such a sentence namespace= "/users". This is

<?xml version= "1.0" encoding= "UTF-8"?>
<! DOCTYPE struts Public "-//apache software foundation//dtd struts Configuration 2.1//en"
"Http://struts.apache.org/dtds/struts-2.1.dtd" >

<struts>
<package name= "Users" extends= "Struts-default" namespace= "/users" >

......

<action name= "Listuser" class= "Listuseraction" >
<result>/users/userList.jsp</result>
</action>

......

</package>

</strusts>

Then start the server from the new, OK, show normal! At the same time we also see the address bar in the action before a "/users", jump to the video is also "/users/userlist.jsp", so that the consistency, the problem is solved.

Reprinted from http://blog.csdn.net/edagarli/article/details/14088065

Struts return JSP style is missing the style path is not correct

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.